简体   繁体   English

为什么无法从队列中获得响应

[英]Why can't get response from queue

I have test that sends message to the activemq queue. 我已经测试过将消息发送到activemq队列。 If I use sendBody than everething is OK, but when I ask for requestBody everething happens exatly but I didn't get respone 如果我使用sendBody胜过一切都可以,但是当我请求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)

It doesn't depent if I use embeded ActiveMQ or start it manually. 如果我使用嵌入式ActiveMQ或手动启动它,它并不会令人沮丧。 Here are my routes: 这是我的路线:

<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>

and test: 并测试:

@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);
    }

What I missed? 我错过了什么?

I don't see a reference to ActiveMQ, but in general sending to a queue is an InOnly operation and an OUT response isn't returned (hence why sendBody works, but requestBody fails)... 我没有看到对ActiveMQ的引用,但是通常发送到队列是InOnly操作,并且不会返回OUT响应(因此sendBody起作用,而requestBody失败)...

if you need InOut behavior, then do something like this... 如果您需要InOut行为,请执行以下操作...

https://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOutSynchronousTest.java https://svn.apache.org/repos/asf/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOutSynchronousTest.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM