You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by bjacob <bo...@gmail.com> on 2012/03/30 19:06:06 UTC

Using Apache Camel ProducerTemplate class to create a JMS message with headers and properties

Hello Everyone - 

I'm new to Apache camel and my question may seem very simple.

I was trying to create a JMS message using Camel with the ProducerTemplate
class. This JMS message will have headers like (JMSReplyTo) and customer
properties (say SOAPHeader etc). 

I couldn't find a 'send' function in the ProducerTemplate class which can be
used to send Body, Headers and Properties. I see sendBodyAndHeaders and
sendBodyAndProperty functions but not for all the three together.

Can someone help me on this?

Thanks
Boney Jacob

--
View this message in context: http://camel.465427.n5.nabble.com/Using-Apache-Camel-ProducerTemplate-class-to-create-a-JMS-message-with-headers-and-properties-tp5607229p5607229.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Apache Camel ProducerTemplate class to create a JMS message with headers and properties

Posted by bjacob <bo...@gmail.com>.
Thank you so much. It is working now.

--
View this message in context: http://camel.465427.n5.nabble.com/Using-Apache-Camel-ProducerTemplate-class-to-create-a-JMS-message-with-headers-and-properties-tp5607229p5607650.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Apache Camel ProducerTemplate class to create a JMS message with headers and properties

Posted by Christian Müller <ch...@gmail.com>.
template.send() will send inOnly exchanges. What you really want to do is
template.request().

Checkout [1] and read the section about the different cases for
ExchangePattern and JMSReplyTo set or not.

[1] http://camel.apache.org/jms.html

Best,
Christian

On Fri, Mar 30, 2012 at 9:02 PM, bjacob <bo...@gmail.com> wrote:

> Thank you for the response.
>
> Now I'm able to send the request but on the server side(or consumer side),
> I
> see a temporary queue name and not the queue name that I'm setting to
> 'JMSReplyTo'. Other than the output not getting pushed to the correct
> queue,
> everything else seems to be fine.
>
> I'm sure that I'm missing some piece here to preserve the queue name.
>
> It would be great if some one can help me with this. I've attached my code
> below.
> --------------------------------------------------------------
>         ProducerTemplate template5 = context.createProducerTemplate();
>
>         String sendQ="ACS.OMS.ms4.13.CustomerChangedNotification.Request";
>         String readQ="ACS.OMS.ms4.13.CustomerChangedNotification.Response";
>         String
> soapAction="
> http://www.multispeak.org/Version_4.1_Release/CustomerChangedNotification
> ";
>
>         hm.put("JMSDestination",sendQ);
>         hm.put("JMSReplyTo",readQ);
>         hm.put("SoapAction", soapAction);
>
>
>         Exchange exchange = new DefaultExchange(context);
>
>         exchange.getIn().setBody(doc);
>         exchange.getIn().setHeaders(hm);
>         exchange.setPattern(ExchangePattern.InOut);
>
>         template5.send("jms:queue:"+sendQ+"?preserveMessageQos=true",
> exchange);
>
>          ConsumerTemplate consumer = context.createConsumerTemplate();
>
>
>         String msg = consumer.receiveBody("jms:queue:"+readQ,
> String.class);
>
>         System.out.println(msg);
> -----------------------------------------------------------------
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Using-Apache-Camel-ProducerTemplate-class-to-create-a-JMS-message-with-headers-and-properties-tp5607229p5607522.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Using Apache Camel ProducerTemplate class to create a JMS message with headers and properties

Posted by bjacob <bo...@gmail.com>.
Thank you for the response.

Now I'm able to send the request but on the server side(or consumer side), I
see a temporary queue name and not the queue name that I'm setting to
'JMSReplyTo'. Other than the output not getting pushed to the correct queue,
everything else seems to be fine. 

I'm sure that I'm missing some piece here to preserve the queue name. 

It would be great if some one can help me with this. I've attached my code
below.
--------------------------------------------------------------
         ProducerTemplate template5 = context.createProducerTemplate();

         String sendQ="ACS.OMS.ms4.13.CustomerChangedNotification.Request";
         String readQ="ACS.OMS.ms4.13.CustomerChangedNotification.Response";
         String
soapAction="http://www.multispeak.org/Version_4.1_Release/CustomerChangedNotification";
         
         hm.put("JMSDestination",sendQ);
         hm.put("JMSReplyTo",readQ);
         hm.put("SoapAction", soapAction);
         
         
         Exchange exchange = new DefaultExchange(context);
        
         exchange.getIn().setBody(doc);
         exchange.getIn().setHeaders(hm);
         exchange.setPattern(ExchangePattern.InOut);

         template5.send("jms:queue:"+sendQ+"?preserveMessageQos=true",
exchange);

          ConsumerTemplate consumer = context.createConsumerTemplate();


         String msg = consumer.receiveBody("jms:queue:"+readQ, 
String.class);

         System.out.println(msg);
-----------------------------------------------------------------

--
View this message in context: http://camel.465427.n5.nabble.com/Using-Apache-Camel-ProducerTemplate-class-to-create-a-JMS-message-with-headers-and-properties-tp5607229p5607522.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Apache Camel ProducerTemplate class to create a JMS message with headers and properties

Posted by Christian Schneider <ch...@die-schneider.net>.
Be aware that camel headers are not jms headers and camel properties are 
not jms properties.

The producerTemplate always means camel headers and properties. You have 
to consult the camel-jms component to see what camel headers
you need to set to change jms headers and properties. As far as I know 
you do not need the camel properties.

http://camel.apache.org/jms.html

Christian


Am 30.03.2012 19:06, schrieb bjacob:
> Hello Everyone -
>
> I'm new to Apache camel and my question may seem very simple.
>
> I was trying to create a JMS message using Camel with the ProducerTemplate
> class. This JMS message will have headers like (JMSReplyTo) and customer
> properties (say SOAPHeader etc).
>
> I couldn't find a 'send' function in the ProducerTemplate class which can be
> used to send Body, Headers and Properties. I see sendBodyAndHeaders and
> sendBodyAndProperty functions but not for all the three together.
>
> Can someone help me on this?
>
> Thanks
> Boney Jacob
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-Apache-Camel-ProducerTemplate-class-to-create-a-JMS-message-with-headers-and-properties-tp5607229p5607229.html
> Sent from the Camel - Users mailing list archive at Nabble.com.


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

Open Source Architect
Talend Application Integration Division http://www.talend.com


Re: Using Apache Camel ProducerTemplate class to create a JMS message with headers and properties

Posted by Christian Müller <ch...@gmail.com>.
It's related to this question which is already answered:
http://camel.465427.n5.nabble.com/ProducerTemplate-for-sending-mails-with-attachements-td5605511.html#a5606572

Best,
Christian

On Fri, Mar 30, 2012 at 7:06 PM, bjacob <bo...@gmail.com> wrote:

> Hello Everyone -
>
> I'm new to Apache camel and my question may seem very simple.
>
> I was trying to create a JMS message using Camel with the ProducerTemplate
> class. This JMS message will have headers like (JMSReplyTo) and customer
> properties (say SOAPHeader etc).
>
> I couldn't find a 'send' function in the ProducerTemplate class which can
> be
> used to send Body, Headers and Properties. I see sendBodyAndHeaders and
> sendBodyAndProperty functions but not for all the three together.
>
> Can someone help me on this?
>
> Thanks
> Boney Jacob
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Using-Apache-Camel-ProducerTemplate-class-to-create-a-JMS-message-with-headers-and-properties-tp5607229p5607229.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>