camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Still problems with InOut JMS
Date Wed, 08 Jul 2009 08:57:53 GMT
On Wed, Jul 8, 2009 at 12:55 AM, Eric Bouer<ericbouer@gmail.com> wrote:
>
> OK Claus, here is what I've got after trying against revision 791824
> I'm using this unit test:  http://pastebin.com/m1138eec9
> http://pastebin.com/m1138eec9
> The mock is satisfied BUT I get this exception right before the test ends:
> JmsProducer:235 - Future timed out: java.util.concurrent.TimeoutException
>
> I added a to(log?showHeaders=true) for the response process and it helped me
> see that JMSCorrelationID of the response message is null.
> At first glance I was sure that it's it.
> Then I tried with a plain ActiveMQ JMS client and made sure it set the
> Correl.ID correctly but it was not that.....
> PS
> I'm using sun-jdk 1.6.0.14 on amd64 Linux.
> Here are the full logs: http://pastebin.com/m46edef88
> http://pastebin.com/m46edef88
>
Hi

As discussed on the #camel irc. When you send the reply you only send
a String body as reply.
What you need to send is

a)
the TextMessage that contains the correlation id. You should be able
to use .setText("My name is") to set your reply text.

b)
use sendBodyAndHeader and also proivde a JMSCorrelationID as a header
with the id from the TextMessage.




>
>
> Claus Ibsen-2 wrote:
>>
>> I'm adding your unit test to camel-jms with the modification about inonly.
>>
>> On Tue, Jul 7, 2009 at 11:30 AM, Claus Ibsen<claus.ibsen@gmail.com> wrote:
>>> Hi
>>>
>>> When you take charge of listening for the JMSReplyTo queue and sending
>>> back a response then you should *not* use InOut
>>>
>>> So change .inOut to .inOnly
>>>
>>> This works on my laptop
>>>            public void configure() throws Exception {
>>>                from("activemq:queue:hello")
>>>                        .inOnly()
>>>                        .process(new Processor() {
>>>                            public void process(Exchange exchange)
>>> throws Exception {
>>>                                exchange.getIn().setBody("What's
your
>>> name");
>>>
>>> exchange.getIn().setHeader("JMSReplyTo", "nameReplyQueue");
>>>                            }
>>>                        })
>>>
>>> .to("activemq:queue:nameRequestor?preserveMessageQos=true");
>>>
>>>                from("activemq:queue:nameReplyQueue").to("mock:result");
>>>            }
>>>
>>>
>>>
>>> On Tue, Jul 7, 2009 at 12:15 AM, Eric Bouer<ericbouer@gmail.com> wrote:
>>>>
>>>> I finally had time to try again the JMSReplyTo issue.
>>>> Going back to  https://issues.apache.org/activemq/browse/CAMEL-1773
>>>> https://issues.apache.org/activemq/browse/CAMEL-1773 .
>>>> I understand that I can set JMSReplyTo header of InOnly message and also
>>>> send it with preserveMessageQos=true. but then camel won't really wait
>>>> for a
>>>> response(i.e won't get an exception when a timeout occures)
>>>> I do want camel to correlate JMS messages and wait for reply but I want
>>>> to
>>>> have control on the JMSReplyTo.
>>>> Can I set the JMSReplyTo of a route that has InOut pattern ?
>>>> It seems to ignore everything I try.
>>>> I'm providing a test case that goes like this:
>>>> A non-camel JMS client  says "Hello I'm here" which is InOnly message.
>>>> (Advisory in real app)
>>>> The server asks  "What's your name?" which is InOut Message, the
>>>> non-camel
>>>> client should reply it's name.
>>>> I want to get the reply "my name is .." in specific queue and not the
>>>> temp
>>>> one camel creates by default.
>>>> I'm not using JmsTemplate to send the request on purpose.
>>>> Thanks again.
>>>> Eric.
>>>>
>>>> ============ Test Code ========
>>>> package org.apache.camel.component.jms;
>>>>
>>>>
>>>> import javax.jms.Destination;
>>>> import javax.jms.TextMessage;
>>>> import org.apache.activemq.camel.component.ActiveMQComponent;
>>>> import org.apache.camel.CamelContext;
>>>> import org.apache.camel.Exchange;
>>>> import org.apache.camel.Processor;
>>>> import org.apache.camel.builder.RouteBuilder;
>>>> import org.apache.camel.component.mock.MockEndpoint;
>>>> import org.apache.camel.test.CamelTestSupport;
>>>>
>>>> import org.springframework.jms.core.JmsTemplate;
>>>> import static
>>>> org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
>>>>
>>>> public class JmsCustomJMSReplyToInOutTest extends CamelTestSupport {
>>>>
>>>>    private ActiveMQComponent amq;
>>>>    private static String MQURI =
>>>> "vm://localhost?broker.persistent=false&broker.useJmx=false";
>>>> //    private static String MQURI = "tcp://amq1:61616";
>>>>
>>>>    public void testCustomJMSReplyToInOut() throws Exception {
>>>>        MockEndpoint mock = getMockEndpoint("mock:result");
>>>>        mock.expectedBodiesReceived("My name is Arnio");
>>>>        // start a inOnly route
>>>>        template.sendBody("activemq:queue:hello", "Hello, I'm here");
>>>> //Advisory
>>>>        // now consume using something that is not Camel
>>>>        Thread.sleep(1000);
>>>>
>>>>        JmsTemplate jms = new
>>>> JmsTemplate(amq.getConfiguration().getConnectionFactory());
>>>>        TextMessage msg = (TextMessage) jms.receive("nameRequestor");
>>>>        assertEquals("What's your name", msg.getText());
>>>>        // there should be a JMSReplyTo so we know where to send the
>>>> reply
>>>>        Destination replyTo = msg.getJMSReplyTo();
>>>>        System.out.println("Reply will be sent to " +
>>>> replyTo.toString());
>>>>        assertEquals("queue://nameReplyQueue", replyTo.toString());
>>>>        // send reply
>>>>        template.sendBody("activemq:" + replyTo.toString(), "My name is
>>>> Arnio");
>>>>        Thread.sleep(2000);
>>>>        assertMockEndpointsSatisfied();
>>>>    }
>>>>
>>>>
>>>>    protected RouteBuilder createRouteBuilder() throws Exception {
>>>>        return new RouteBuilder() {
>>>>
>>>>            public void configure() throws Exception {
>>>>                from("activemq:queue:hello")
>>>>                        .inOut()
>>>>                        .process(new Processor() {
>>>>                        public void process(Exchange exchange)
throws
>>>> Exception {
>>>>                            exchange.getIn().setHeader("JMSReplyTo",
>>>> "nameReplyQueue");
>>>>                            exchange.getOut().setBody("What's
your
>>>> name");
>>>>                            exchange.getOut().setHeader("JMSReplyTo",
>>>> "nameReplyQueue"); //this should be enough
>>>>                            }
>>>>                        })
>>>>
>>>>  .setHeader("JMSReplyTo",constant("nameReplyQueue"))
>>>> // maybe this ?
>>>>
>>>> .setProperty("JMSReplyTo",constant("nameReplyQueue")) // or this ?
>>>>
>>>> .to("activemq:queue:nameRequestor?preserveMessageQos=true");
>>>>                        //this will force JMSReplyTo but won't
correlate
>>>> later.
>>>>
>>>> //.to("activemq:queue:nameRequestor?replyTo=queue:nameReplyQueue");
>>>>
>>>>                from("activemq:queue:nameReplyQueue").to("mock:result");
>>>>            }
>>>>        };
>>>>    }
>>>>   protected CamelContext createCamelContext() throws Exception {
>>>>        CamelContext camelContext = super.createCamelContext();
>>>>        amq = activeMQComponent(MQURI);
>>>>        camelContext.addComponent("activemq", amq);
>>>>        return camelContext;
>>>>    }
>>>> }
>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Still-problems-with-InOut-JMS-tp24363764p24363764.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Still-problems-with-InOut-JMS-tp24363764p24382811.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Mime
View raw message