我有测试将消息发送到activemq队列。 如果我使用sendBody而不是everething就可以,但是当我要求requestBody时,事情发生得很彻底,但我没有得到反应
org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[Message: com.qqq.dw.beans.invocations.Ping@10699ea]
at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1237)
at org.apache.camel.util.ExchangeHelper.extractResultBody(ExchangeHelper.java:509)
at org.apache.camel.impl.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:442)
at org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:120)
at org.apache.camel.impl.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:264)
at functional.RoutesFunctionalTest.testDirectEndpoint1(RoutesFunctionalTest.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:182)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: ID-Dimas-PC-61919-1341382148513-0-2 not received. Exchange[Message: com.qqq.dw.beans.invocations.Ping@10699ea]
at org.apache.camel.component.jms.reply.ReplyManagerSupport.processReply(ReplyManagerSupport.java:126)
如果我使用嵌入式ActiveMQ或手动启动它,它并不依赖。 这是我的路线:
<routeContext id="dwContext" xmlns="http://camel.apache.org/schema/spring">
<route trace="true">
<from ref="dwQueueEndpoint"/>
<to uri="direct:dwEndpoint"/>
</route>
<route trace="true">
<from uri="direct:dwEndpoint"/>
<to uri="direct:dw.dispatch"/>
</route>
<route id="dwDispatcherRoute" trace="true">
<from uri="direct:dw.dispatch"/>
<doTry>
<to uri="direct:dw.dispatchRequest"/>
<doCatch>
<exception>com.qqq.dw.listener.exceptions.ListenerException</exception>
<to uri="direct:dw.ExpectedError"/>
</doCatch>
<doCatch>
<exception>org.apache.camel.CamelException</exception>
<exception>org.apache.camel.RuntimeCamelException</exception>
<exception>java.lang.Exception</exception>
<to uri="direct:dw.Error"/>
</doCatch>
<doFinally>
<to uri="direct:dw.ResponsePublisher"/>
</doFinally>
</doTry>
</route>
<route id="dwDispatcherSwitchRoute">
<from uri="direct:dw.dispatchRequest"/>
<choice>
<when>
<simple>${body} is 'com.qqq.dw.beans.invocations.Ping'</simple>
<log loggingLevel="DEBUG" message="Processing Ping invocation"/>
<to uri="direct:dw.Ping"/>
</when>
</choice>
</route>
<route id="dwPingRoute">
<from uri="direct:dw.Ping"/>
<to uri="bean:pingInitializer"/>
<to uri="bean:pingValidator"/>
<to uri="bean:pingProcessor"/>
<to uri="bean:pingFinalizer"/>
</route>
<route id="dwErrorRoute">
<from uri="direct:dw.Error"/>
<to uri="bean:dwUnknownErrorExceptionProcessor"/>
</route>
<route id="dwExpectedErrorRoute">
<from uri="direct:dw.ExpectedError"/>
<to uri="bean:dwExceptionProcessor"/>
</route>
<route id="dwResponsePublisherRoute">
<from uri="direct:dw.ResponsePublisher"/>
<to uri="bean:dwResponsePublisher"/>
</route>
</routeContext>
并测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/dw-listener-test-jms-client.xml"})
public class RoutesFunctionalTest {
@Autowired
ProducerTemplate producerTemplate;
@Before
public void before() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
"/dw-listener-test-jms-server.xml"
);
}
@Test
public void testDirectEndpoint1() throws Exception {
Ping invocation = new Ping();
invocation.setRequestId("123456789");
invocation.setMessage("PING-PING-PING");
invocation.setRequestTime(new Date().getTime());
Object o = producerTemplate.requestBody(invocation);
Thread.sleep(3000);
assertNotNull(o);
}
我错过了什么?
答案 0 :(得分:0)
我没有看到对ActiveMQ的引用,但通常发送到队列是InOnly操作并且不返回OUT响应(因此sendBody工作原理,但requestBody失败)...
如果你需要InOut行为,那就做这样的事情......