You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Tomas <to...@atos.net> on 2014/05/29 09:15:07 UTC

Request/reply JMS (ActiveMQ)

Hi guys, 
I am pretty new in Camel... I'd like to implement a simple Request/reply for
messaging with this behavior:

1. Requestor sends a message to a queue 
2. Replier listens on the queue, gets asynchronously the message and replies
to JMSReplyTo header of the message
3. Requestor receives the reply

I've got this code:

from("jms:queue:MyQ").setExchangePattern(ExchangePattern.InOut).to("jms:queue:MyQ");

1. and 2. works fine, the requestor sends the msg to MyQ (without any
setting of the headers on the app level), and the repliers gets the msg from
MyQ with set JMSCorrelationID and JMSReplyTo by Camel.

The problem is that JMSReplyTo is not know to the requestor, so it cannot
wait on the temp queue for the reply...

Is there a solution?

Thank you



--
View this message in context: http://camel.465427.n5.nabble.com/Request-reply-JMS-ActiveMQ-tp5751686.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Request/reply JMS (ActiveMQ)

Posted by Christian Schneider <ch...@die-schneider.net>.
Perhaps I did not make this clear enough. You should not use from(jms) 
and to(jms) in the same route.

Simply send for example like this:
from("direct:test1").to("jms:queue:MyQ")

The to part will automatically send a message, set the replyTo, open a 
temp queue for the reply, wait for a reply, receive it and return it an 
set it as the new body.


Then in your main route your simply do
from("jms:queue:MyQ").process(...)

This simple from listens on MyQ for messages, sets the message as body 
on the route, Forwards to the next processor. Then at the end of the 
route the body that is in the message is given back to the from which 
sends the content to the queue named in the jmsReplyTo header of the 
orig message.

So to put it shortly just use a single to(jms) to send and receive and 
use a single from(jms) to receive and send back the reply.

Christian

On 29.05.2014 09:57, Tomas wrote:
> Hi Christian, thank you for the reply.
>
> Yes, I can add a processor in between and send it back to MyQ like this:
>
> from("jms:queue:MyQ").process(...).to("jms:queue:MyQ");
>
> But this is not what I need. I want to listen to the MyQ, receive it and
> then send a new message as a reply to the destination defined by JMSReplyTo
> (which was already set my Camel's InOut) and of course bind the request map
> to the replies by JMSCorrelationId (set by Camel as well).
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Request-reply-JMS-ActiveMQ-tp5751686p5751689.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com


Re: Request/reply JMS (ActiveMQ)

Posted by Tomas <to...@atos.net>.
Hi Christian, thank you for the reply.

Yes, I can add a processor in between and send it back to MyQ like this:

from("jms:queue:MyQ").process(...).to("jms:queue:MyQ");

But this is not what I need. I want to listen to the MyQ, receive it and
then send a new message as a reply to the destination defined by JMSReplyTo
(which was already set my Camel's InOut) and of course bind the request map
to the replies by JMSCorrelationId (set by Camel as well).




--
View this message in context: http://camel.465427.n5.nabble.com/Request-reply-JMS-ActiveMQ-tp5751686p5751689.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Request/reply JMS (ActiveMQ)

Posted by Christian Schneider <ch...@die-schneider.net>.
Hi Thomas,

camel does the receive as well as the reply in the from("jms:queue:myQ").

So what you try to achieve can simply be done with:

from("jms:queue:MyQ")...

Simply start your listener route with this and do some processing on the route. The body that is set at the end of the route is then automatically sent to the requestor.
See http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html

For the requestor a simple to("jms:queue:MyQ") at the end of the route will send the message as well as receive the reply.

Christian




On 29.05.2014 09:15, Tomas wrote:
> Hi guys,
> I am pretty new in Camel... I'd like to implement a simple Request/reply for
> messaging with this behavior:
>
> 1. Requestor sends a message to a queue
> 2. Replier listens on the queue, gets asynchronously the message and replies
> to JMSReplyTo header of the message
> 3. Requestor receives the reply
>
> I've got this code:
>
> from("jms:queue:MyQ").setExchangePattern(ExchangePattern.InOut).to("jms:queue:MyQ");
>
> 1. and 2. works fine, the requestor sends the msg to MyQ (without any
> setting of the headers on the app level), and the repliers gets the msg from
> MyQ with set JMSCorrelationID and JMSReplyTo by Camel.
>
> The problem is that JMSReplyTo is not know to the requestor, so it cannot
> wait on the temp queue for the reply...
>
> Is there a solution?
>
> Thank you
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Request-reply-JMS-ActiveMQ-tp5751686.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com


Re: Request/reply JMS (ActiveMQ)

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, May 29, 2014 at 9:15 AM, Tomas <to...@atos.net> wrote:
> Hi guys,
> I am pretty new in Camel... I'd like to implement a simple Request/reply for
> messaging with this behavior:
>
> 1. Requestor sends a message to a queue
> 2. Replier listens on the queue, gets asynchronously the message and replies
> to JMSReplyTo header of the message
> 3. Requestor receives the reply
>
> I've got this code:
>
> from("jms:queue:MyQ").setExchangePattern(ExchangePattern.InOut).to("jms:queue:MyQ");
>

Camel will automatic send back a reply if a JMSReplyTo header is included.

So all you need to do is

from("jms:queue:MyQ")
   .. do somethere here to process and set a response you want



> 1. and 2. works fine, the requestor sends the msg to MyQ (without any
> setting of the headers on the app level), and the repliers gets the msg from
> MyQ with set JMSCorrelationID and JMSReplyTo by Camel.
>
> The problem is that JMSReplyTo is not know to the requestor, so it cannot
> wait on the temp queue for the reply...
>
> Is there a solution?
>
> Thank you
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Request-reply-JMS-ActiveMQ-tp5751686.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/