You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by FCasale <fa...@hotmail.com> on 2009/12/04 00:34:39 UTC

Request-Response with Producer/Consumer Templates


I've created a ProducerTemplate on the client side and I'm sending a message
like:

producer.sendBody("test-jms:queue:test.queue?exchangePattern=InOut", "Test
Message");

and I see it waiting for a response in the logged DEBUG statements....

Good...

I've created a ConsumerTemplate on the server side and get the message
complete with a JMSReplyTo

Great...

But it's not clear to me how a send a response on the server side with the
ProducerTemplate or what's actually being called on the client side when it
gets the response message?

I do see the client thread waiting on the above sendBody instruction as it
waits for the response... but it's not like the sendBody returns an object,
it's a void returning method.

I'm just looking to start with a simple programmatic request-reply example
using these Producer / Consumer Templates from the Camel context... 


-- 
View this message in context: http://old.nabble.com/Request-Response-with-Producer-Consumer-Templates-tp26635175p26635175.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Request-Response with Producer/Consumer Templates

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

What JMS Broker are you using?

I do think brokers can mess with the correlation id so its not always
as strait forward as people think with JMS.
And what version of Camel are you using?


On Tue, Dec 8, 2009 at 6:29 AM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> If you create a route on the server side, then Camel should take care
> of it all. As it can detect the JMSReplyTo header and know where to
> send the reply with the correlation id etc.
>
>
>
> On Tue, Dec 8, 2009 at 1:39 AM, FCasale <fa...@hotmail.com> wrote:
>>
>>
>> Thanks, I am much closer now... I'm just not sure how to set the
>> correlationId for the reply message.
>>
>> It is coming back correlationId=null and is therefore ignored.
>>
>> On the server side I am trying this:
>>
>> --------------
>>
>> Exchange exch = consumer.receive("test-jms:queue:test.queue");
>> Message msg = exch.getIn();
>>
>> producer.sendBodyAndHeader(msg.getHeader("JMSReplyTo").toString(), "Ho Ho",
>> "JMSCorrelationId", msg.getHeader("JMSCorrelationId").toString());
>>
>> --------------
>>
>> So the message is replying on the correct temporary queue... but with no
>> correlationId so the response message is being ignored....
>>
>> How do I set the correlationId on the response message?
>>
>> --
>> View this message in context: http://old.nabble.com/Request-Response-with-Producer-Consumer-Templates-tp26635175p26686915.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Request-Response with Producer/Consumer Templates

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

If you create a route on the server side, then Camel should take care
of it all. As it can detect the JMSReplyTo header and know where to
send the reply with the correlation id etc.



On Tue, Dec 8, 2009 at 1:39 AM, FCasale <fa...@hotmail.com> wrote:
>
>
> Thanks, I am much closer now... I'm just not sure how to set the
> correlationId for the reply message.
>
> It is coming back correlationId=null and is therefore ignored.
>
> On the server side I am trying this:
>
> --------------
>
> Exchange exch = consumer.receive("test-jms:queue:test.queue");
> Message msg = exch.getIn();
>
> producer.sendBodyAndHeader(msg.getHeader("JMSReplyTo").toString(), "Ho Ho",
> "JMSCorrelationId", msg.getHeader("JMSCorrelationId").toString());
>
> --------------
>
> So the message is replying on the correct temporary queue... but with no
> correlationId so the response message is being ignored....
>
> How do I set the correlationId on the response message?
>
> --
> View this message in context: http://old.nabble.com/Request-Response-with-Producer-Consumer-Templates-tp26635175p26686915.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Request-Response with Producer/Consumer Templates

Posted by FCasale <fa...@hotmail.com>.

Thanks, I am much closer now... I'm just not sure how to set the
correlationId for the reply message.

It is coming back correlationId=null and is therefore ignored.

On the server side I am trying this:

--------------

Exchange exch = consumer.receive("test-jms:queue:test.queue");
Message msg = exch.getIn();

producer.sendBodyAndHeader(msg.getHeader("JMSReplyTo").toString(), "Ho Ho",
"JMSCorrelationId", msg.getHeader("JMSCorrelationId").toString());

--------------

So the message is replying on the correct temporary queue... but with no
correlationId so the response message is being ignored....

How do I set the correlationId on the response message?
			
-- 
View this message in context: http://old.nabble.com/Request-Response-with-Producer-Consumer-Templates-tp26635175p26686915.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Request-Response with Producer/Consumer Templates

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Use requestBody for request/reply messaging (aka InOut) and then you
dont need to set exchangePattern=InOut on the URI.

String reply = producer.requestBody("test-jms:queue.test.queue", String.class);



On Fri, Dec 4, 2009 at 12:34 AM, FCasale <fa...@hotmail.com> wrote:
>
>
> I've created a ProducerTemplate on the client side and I'm sending a message
> like:
>
> producer.sendBody("test-jms:queue:test.queue?exchangePattern=InOut", "Test
> Message");
>
> and I see it waiting for a response in the logged DEBUG statements....
>
> Good...
>
> I've created a ConsumerTemplate on the server side and get the message
> complete with a JMSReplyTo
>
> Great...
>
> But it's not clear to me how a send a response on the server side with the
> ProducerTemplate or what's actually being called on the client side when it
> gets the response message?
>
> I do see the client thread waiting on the above sendBody instruction as it
> waits for the response... but it's not like the sendBody returns an object,
> it's a void returning method.
>
> I'm just looking to start with a simple programmatic request-reply example
> using these Producer / Consumer Templates from the Camel context...
>
>
> --
> View this message in context: http://old.nabble.com/Request-Response-with-Producer-Consumer-Templates-tp26635175p26635175.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus