You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Marco Crivellaro <ma...@gmail.com> on 2013/02/26 17:59:17 UTC

camel processor in InOut to send 2 replies

Hi All,
I have a requirement to send 2 messages in as reply of a request using InOut
pattern.
How can I achieve this?

My route looks as following:

  <camelContext id="hulkcontext"
xmlns="http://camel.apache.org/schema/spring" autoStartup="true">
    
    <route>
   		<from uri="jms:queue:data"/>
   		<to uri="bean:myMessageProcessor"/>
   		<inOut uri="mock:dataresult" />   		
	</route>
  </camelContext>


I've got a processor working properly when sending a single reply but in
some situations 2 messages have to be sent.



--
View this message in context: http://camel.465427.n5.nabble.com/camel-processor-in-InOut-to-send-2-replies-tp5728189.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel processor in InOut to send 2 replies

Posted by Christian Müller <ch...@gmail.com>.
Will the following work for you (using Java DSL)?

from("jms:queue:data")
  .setHeader("id", constant("1"))
  .multicast()
    .inOnly("jms:queue:first", "jms:queue:second");

from("jms:queue:first")
  .to("bean:myMessageProcessor")
  .to("jms:queue:finished");

from("jms:queue:second")
  .to("bean:myMessageProcessor")
  .to("jms:queue:finished");

from("jms:queue:finished")
  .aggregate(header("id"), new YourAggregatingStrategy()).completionSize(2)
  .to("mock:dataresult");

Best,
Christian

On Wed, Feb 27, 2013 at 2:55 PM, Marco Crivellaro <ma...@gmail.com>wrote:

> Hi Hadrian,
> thanks for your reply. Sorry if I've been unclear.
> The messages I am publishing to the In queue have JMSReplyTo header set.
>
>
>  As you suggested I've used the reply to header to send an additional
> message using a bespoke producer in the process method of the Processor:
>
>
>         javax.jms.Destination replyTo =
> exchange.getIn().getHeader("JMSReplyTo", javax.jms.Destination.class);
>         JmsEndpoint replyEndpoint = new JmsEndpoint();
>         replyEndpoint.setDestination(replyTo);
>         DefaultProducerTemplate producer = (DefaultProducerTemplate)
> exchange.getContext().createProducerTemplate();
>
> producer.sendBodyAndHeaders(replyEndpoint.getEndpointUri().toString(),
> "TEST", exchange.getOut().getHeaders());
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/camel-processor-in-InOut-to-send-2-replies-tp5728189p5728230.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--

Re: camel processor in InOut to send 2 replies

Posted by Marco Crivellaro <ma...@gmail.com>.
Hi Hadrian,
thanks for your reply. Sorry if I've been unclear.
The messages I am publishing to the In queue have JMSReplyTo header set.


 As you suggested I've used the reply to header to send an additional
message using a bespoke producer in the process method of the Processor:


    	javax.jms.Destination replyTo =
exchange.getIn().getHeader("JMSReplyTo", javax.jms.Destination.class);
    	JmsEndpoint replyEndpoint = new JmsEndpoint();
    	replyEndpoint.setDestination(replyTo);  	
    	DefaultProducerTemplate producer = (DefaultProducerTemplate)
exchange.getContext().createProducerTemplate(); 
    	producer.sendBodyAndHeaders(replyEndpoint.getEndpointUri().toString(),
"TEST", exchange.getOut().getHeaders());



--
View this message in context: http://camel.465427.n5.nabble.com/camel-processor-in-InOut-to-send-2-replies-tp5728189p5728230.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: camel processor in InOut to send 2 replies

Posted by Hadrian Zbarcea <hz...@gmail.com>.
Your question is not very clear, I could interpret it in a few ways. 
Your example seems to indicate an in-only, no reply pattern.

Firstly, you cannot do what you need with a request/reply pattern, so 
you certainly have something else. Since you use jms, you probably use a 
reply queue [1]. That is based on the standard JMSReplyTo header. What 
you'd have to do use is read that header and send the extra message(s) 
yourself. Sema if you need to send to a different queue, except you need 
to find a way to send across the 2nd reply queue name yourself.

I hope this helps,
Hadrian


[1] http://camel.apache.org/jms.html (read the Request-reply over JMS 
section).


On 02/26/2013 11:59 AM, Marco Crivellaro wrote:
> Hi All,
> I have a requirement to send 2 messages in as reply of a request using InOut
> pattern.
> How can I achieve this?
>
> My route looks as following:
>
>    <camelContext id="hulkcontext"
> xmlns="http://camel.apache.org/schema/spring" autoStartup="true">
>
>      <route>
>     		<from uri="jms:queue:data"/>
>     		<to uri="bean:myMessageProcessor"/>
>     		<inOut uri="mock:dataresult" />   		
> 	</route>
>    </camelContext>
>
>
> I've got a processor working properly when sending a single reply but in
> some situations 2 messages have to be sent.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/camel-processor-in-InOut-to-send-2-replies-tp5728189.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>