必须指定Camel netty计时器错误

时间:2014-12-04 15:02:30

标签: java apache-camel netty

我正试图以这种方式向netty端点发送消息:

new DefaultCamelContext().createProducerTemplate().sendBody("netty:tcp://localhost:5150", "dummy");

我收到了错误:

org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: netty://tcp://localhost:5150 due to: timer must be specified
    at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:480)
    at org.apache.camel.impl.DefaultProducerTemplate.resolveMandatoryEndpoint(DefaultProducerTemplate.java:436)
    at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:130)
    at com.company.RouteDebugHelper.sendMessage(RouteDebugHelper.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalArgumentException: timer must be specified
    at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:290)
    at org.apache.camel.component.netty.NettyEndpoint.doStart(NettyEndpoint.java:88)
    at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:60)
    at org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:1769)
    at org.apache.camel.impl.DefaultCamelContext.doAddService(DefaultCamelContext.java:932)
    at org.apache.camel.impl.DefaultCamelContext.addService(DefaultCamelContext.java:893)
    at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:476)
    ... 26 more

这个错误究竟是什么?我怎么能解决这个问题呢? 我已经阅读了this次讨论,但我找不到答案。

1 个答案:

答案 0 :(得分:1)

NettyComponent只是在启动时设置计时器。所以你需要首先启动camel上下文,这样CamelContext可以默认启动组件。

 CamelContext context = new DefaultCamelContext();
 context.start();
 context.createProducerTemplate().sendBody("netty:tcp://localhost:5150", "dummy");