You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by kumaap <am...@gmail.com> on 2010/09/02 12:16:53 UTC

Setting JMS ReplyTo

Camel version 2.4

I'm trying to set the JMS reply To. But it seems to be ignoring the
property.
Ive been reading some posts but still cant get it to work.

In my use case my route subscribes from a custom component and publishes to
a JMS queue.

Ive tried setting the header and also setting the replTo property

Ive provided this test code that shows teh properties not getting set 

package sandbox;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.*;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.component.jms.JmsMessageType;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spring.SpringCamelContext;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Assert;
import org.junit.Before;
import org.springframework.context.support.GenericApplicationContext;


public class JMSReplyToTest extends CamelTestSupport {

    private ActiveMQConnectionFactory factory;
    private SpringCamelContext camelContext;

    @EndpointInject(uri = "mock:result")
    protected MockEndpoint resultEndpoint;

    @Produce(uri = "direct:start")
    protected ProducerTemplate template;

    @Before
    public void setUp() throws Exception {

        factory = new ActiveMQConnectionFactory("vm://local");
        super.setUp();
    }


    @org.junit.Test
    public void test() throws Exception {
        template.sendBody("test");
        resultEndpoint.expectedMessageCount(1);
       
Assert.assertTrue(resultEndpoint.getExchanges().get(0).getIn().getHeader("test")
!= null);
       
Assert.assertTrue(resultEndpoint.getExchanges().get(0).getIn().getHeader("test").equals("test"));
       
Assert.assertTrue(resultEndpoint.getExchanges().get(0).getIn().getHeader("JMSReplyTo")
!= null);
       
Assert.assertTrue(resultEndpoint.getExchanges().get(0).getIn().getHeader("JMSReplyTo").equals("SYSTEM.SOAP.RESPONSE.QUEUE"));
        resultEndpoint.assertIsSatisfied();
    }

    @Override
    protected CamelContext createCamelContext() throws Exception {
        GenericApplicationContext applicationContext = new
GenericApplicationContext();
        camelContext = new SpringCamelContext(applicationContext);
        JmsComponent jmsComponent = new JmsComponent();
        jmsComponent.setConnectionFactory(factory);
        applicationContext.getBeanFactory().registerSingleton("jms",
jmsComponent);
        return camelContext;
    }

    @Override
    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {
                from("direct:start").setHeader("JMSReplyTo",
constant("queue:SYSTEM.SOAP.RESPONSE.QUEUE")).setHeader("test",
constant("test")).to("jms:result?replyTo=queue://SYSTEM.SOAP.RESPONSE.QUEUE");
                from("jms:result").to("mock:result");
            }
        };
    }


}


-- 
View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2800345.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Setting JMS ReplyTo

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Sep 3, 2010 at 5:36 PM, kumaap <am...@gmail.com> wrote:
>
> Cheers Mate

Code committed to trunk. Could you try it on your system?


> --
> View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2802410.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: Setting JMS ReplyTo

Posted by kumaap <am...@gmail.com>.
Cheers Mate 
-- 
View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2802410.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Setting JMS ReplyTo

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Sep 3, 2010 at 3:14 PM, kumaap <am...@gmail.com> wrote:
>
> I have run the test with Active MQ and it doesn't work .
>
> It doesnt matter about which JMS provider your using here. But im using
> Websphere MQ.
>
> JMSReplyTo is not a JMS header property as such its is set explicitly with a
> javax.jms.Destination object not a string. I don't know how you got your
> unittest to work as the code in
> org.apache.camel.component.jms.JmsBinding.appendJmsProperty would reject the
> property.
>
> The javax.jms.Message interface
>  void setJMSReplyTo(javax.jms.Destination destination) throws
> javax.jms.JMSException;
>
> I can create a processor to do this , but its sounds like a simpler to
> change the JmsProducer, this does look a like a feature others would use.
>

I have created a ticket to track this
https://issues.apache.org/activemq/browse/CAMEL-3102

Then it may be easier for you on WebSphereMQ as the JmsProducer will
lookup or create the JMSReplyTo destination.



> Cheers
> Amitesh
> --
> View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2802144.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: Setting JMS ReplyTo

Posted by kumaap <am...@gmail.com>.
I have run the test with Active MQ and it doesn't work . 

It doesnt matter about which JMS provider your using here. But im using
Websphere MQ.

JMSReplyTo is not a JMS header property as such its is set explicitly with a
javax.jms.Destination object not a string. I don't know how you got your
unittest to work as the code in
org.apache.camel.component.jms.JmsBinding.appendJmsProperty would reject the
property.

The javax.jms.Message interface 
  void setJMSReplyTo(javax.jms.Destination destination) throws
javax.jms.JMSException;

I can create a processor to do this , but its sounds like a simpler to
change the JmsProducer, this does look a like a feature others would use.

Cheers
Amitesh
-- 
View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2802144.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Setting JMS ReplyTo

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Sep 3, 2010 at 11:11 AM, kumaap <am...@gmail.com> wrote:
>
> Hi,
>
> I don't know how you got the unit test to work as its not running with camel
> 2.4 . I can see why JMSReplyTo should be a destination object but the unit
> test its a string.
>
> The JmsBinding.makeJmsMessage executes the appendJmsProperties
>
> "
> else if (headerName.equals("JMSReplyTo") && headerValue != null) {
>
> jmsMessage.setJMSReplyTo(ExchangeHelper.convertToType(exchange,
> Destination.class, headerValue));"
>
> There is no converter to convert a string to a destination so it will always
> be null.
>

Thats part of ActiveMQ.

> And you cant just create a Destination object unless you have a JMS Session.
>

What JMS broker are you using?

I would assume the JMSReplyTo value can contains some string which
indicate which queue to reply. If not then its your job to add the
Destination type yourself.

For example you can leverage Spring's resolver for that
org.springframework.jms.support.destination.DestinationResolver

Which you may be able to google and find solutions with your JMS
broker (if you are not using AMQ)


> Cheers
> Amitesh
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2801917.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: Setting JMS ReplyTo

Posted by kumaap <am...@gmail.com>.
Hi,

I don't know how you got the unit test to work as its not running with camel
2.4 . I can see why JMSReplyTo should be a destination object but the unit
test its a string.

The JmsBinding.makeJmsMessage executes the appendJmsProperties

"
else if (headerName.equals("JMSReplyTo") && headerValue != null) {
               
jmsMessage.setJMSReplyTo(ExchangeHelper.convertToType(exchange,
Destination.class, headerValue));"

There is no converter to convert a string to a destination so it will always
be null.

And you cant just create a Destination object unless you have a JMS Session.

Cheers
Amitesh


 





 




-- 
View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2801917.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Setting JMS ReplyTo

Posted by Claus Ibsen <cl...@gmail.com>.
Ah okay

You just want to send a fire and forget message but it should have the
JMSReplyTo header set.

Then see this unit test
http://svn.apache.org/viewvc?rev=992224&view=rev


On Thu, Sep 2, 2010 at 8:03 PM, kumaap <am...@gmail.com> wrote:
>
> It seems the in the JmsProducer  when processing InOnly it ignores the
> replyTo property
>
> MessageCreator messageCreator = new MessageCreator() {
>            public Message createMessage(Session session) throws
> JMSException {
>                return endpoint.getBinding().makeJmsMessage(exchange, in,
> session, null);
>            }
>        };
> the makeJmsMessage method cant convert String to Destination which makes
> sense
>
> maybe the message creator for processInOnly should be more like this,
> considering you need a session to create a destination
>
> MessageCreator messageCreator = new MessageCreator() {
>            public Message createMessage(Session session) throws
> JMSException {
>                Message message =
> endpoint.getBinding().makeJmsMessage(exchange, in, session, null);
>                if(endpoint.getReplyTo() != null){
>                         Destination reply =
> session.createQueue(endpoint.getReplyTo()); <-- maybe detect if its a queue
> or topic by checking the suffix of endpoint.getReplyTo() first
>                         message.setJMSReplyTo(reply);
>                }
>                return message ;
>            }
>        };
>
> If this is not the way to set JMSReplyTo can you point me in the correct
> direction. What i Don't want to do is subscribe to the JMSReplyTo
> destination.
> --
> View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2801138.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: Setting JMS ReplyTo

Posted by kumaap <am...@gmail.com>.
It seems the in the JmsProducer  when processing InOnly it ignores the
replyTo property

MessageCreator messageCreator = new MessageCreator() {
            public Message createMessage(Session session) throws
JMSException {
                return endpoint.getBinding().makeJmsMessage(exchange, in,
session, null);
            }
        };
the makeJmsMessage method cant convert String to Destination which makes
sense 

maybe the message creator for processInOnly should be more like this,
considering you need a session to create a destination

MessageCreator messageCreator = new MessageCreator() {
            public Message createMessage(Session session) throws
JMSException {
                Message message =
endpoint.getBinding().makeJmsMessage(exchange, in, session, null);
                if(endpoint.getReplyTo() != null){
                         Destination reply =
session.createQueue(endpoint.getReplyTo()); <-- maybe detect if its a queue
or topic by checking the suffix of endpoint.getReplyTo() first 
                         message.setJMSReplyTo(reply);
                }
                return message ;
            }
        };

If this is not the way to set JMSReplyTo can you point me in the correct
direction. What i Don't want to do is subscribe to the JMSReplyTo
destination.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2801138.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Setting JMS ReplyTo

Posted by kumaap <am...@gmail.com>.
I'm not going to be doing the request/replay i just want to set the value.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2800855.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Setting JMS ReplyTo

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Sep 2, 2010 at 5:13 PM, kumaap <am...@gmail.com> wrote:
>
> Hi Claus
>
> I don't think disableReplyTo property is working  either
>
>  public void configure() {
>                from("direct:start").setHeader("test",
> constant("test")).to("jms:F.PUB);
>            }
>
> And i get
> [ 2010-09-02 15:56:34,335 ][ DEBUG ][
> org.apache.camel.component.jms.JmsProducer.processInOut(JmsProducer.java:222)
> ][ main ][ Message sent, now waiting for reply at: queue://bar ]
>
> If i set the exchange pattern to InOnly then the replyTo property isnt set

Oh course the MEP must be InOut to do request/reply over JMS.


> --
> View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2800827.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: Setting JMS ReplyTo

Posted by kumaap <am...@gmail.com>.
Hi Claus

I don't think disableReplyTo property is working  either 

 public void configure() {
                from("direct:start").setHeader("test",
constant("test")).to("jms:F.PUB);
            }

And i get 
[ 2010-09-02 15:56:34,335 ][ DEBUG ][ 
org.apache.camel.component.jms.JmsProducer.processInOut(JmsProducer.java:222)
][ main ][ Message sent, now waiting for reply at: queue://bar ] 

If i set the exchange pattern to InOnly then the replyTo property isnt set 
-- 
View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2800827.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Setting JMS ReplyTo

Posted by kumaap <am...@gmail.com>.
Ok ive go my unit test to work 

by changing sendBody to 

template.request("direct:start",new Processor() {
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setBody("Moon");
            }
        });

But bellow is my realife problem , which is still not working , the replyTo
isnt getting set 		

<?xml version="1.0" encoding="UTF-8"?>
<route xmlns="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       autoStartup="false" errorHandlerRef="errorHandler" group="o1"
id="v_to_app2_iso" trace="true"
       xsi:schemaLocation="http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
    <from uri="rulesEngine:app2iso"/>
    <to uri="ciblToXml"/>
    <to uri="xmlToString"/>
    <to uri="stringToJmsText"/>
    <setHeader headerName="soapAction">
        <constant>http://test/wcf/sample/OnMessage</constant>
    </setHeader>
    <setHeader headerName="endpointURL">
       
<constant>jms:/queue?destination=F.WCF.ST@EBVVQM1&amp;connectionFactory=connectQueueManager(EBVVQM1)binding(client)clientChannel(SVR.F.WCF.ST)clientConnection(aurora(6401))sslKeyRepository(RootsAndDummyCert)sslCipherSpec(TRIPLE_DES_SHA_US)&amp;initialContextFactory=com.ibm.mq.jms.Nojndi</constant>
    </setHeader>
    <to
uri="jms:cn=q_to_app2_iso?transacted=true&amp;replyTo=SYSTEM.SOAP.RESPONSE.QUEUE&amp;jmsMessageType=Text&amp;connectionFactoryName=qcf_orac_to_app2_iso&amp;username=${route.mqm.user}&amp;password=${route.mqm.password}"/>
</route>
-- 
View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2800721.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Setting JMS ReplyTo

Posted by Claus Ibsen <cl...@gmail.com>.
Just play with the working unit test and adapt it to your style, then
you most likely is getting it to work.



On Thu, Sep 2, 2010 at 1:52 PM, kumaap <am...@gmail.com> wrote:
>
> Hi Claus,
>
> Im looking through the unit test
> JmsRequestReplyFixedReplyToInEndpointTest
>
> I can run and it works fine.
>
> But i cant see my mistake.
> @Override
>    protected RouteBuilder createRouteBuilder() {
>        return new RouteBuilder() {
>            public void configure() {
>
> from("direct:start").to("jms:result?replyTo=SYSTEM.SOAP.RESPONSE.QUEUE");
>                from("jms:result").to("mock:result");
>            }
>        };
>    }
> --
> View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2800407.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: Setting JMS ReplyTo

Posted by kumaap <am...@gmail.com>.
Hi Claus,

Im looking through the unit test 
JmsRequestReplyFixedReplyToInEndpointTest

I can run and it works fine.

But i cant see my mistake.
@Override
    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {
               
from("direct:start").to("jms:result?replyTo=SYSTEM.SOAP.RESPONSE.QUEUE");
                from("jms:result").to("mock:result");
            }
        };
    }
-- 
View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2800407.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Setting JMS ReplyTo

Posted by Claus Ibsen <cl...@gmail.com>.
Check some of the unit tests in camel-jms

On Thu, Sep 2, 2010 at 12:16 PM, kumaap <am...@gmail.com> wrote:
>
> Camel version 2.4
>
> I'm trying to set the JMS reply To. But it seems to be ignoring the
> property.
> Ive been reading some posts but still cant get it to work.
>
> In my use case my route subscribes from a custom component and publishes to
> a JMS queue.
>
> Ive tried setting the header and also setting the replTo property
>
> Ive provided this test code that shows teh properties not getting set
>
> package sandbox;
>
> import org.apache.activemq.ActiveMQConnectionFactory;
> import org.apache.camel.*;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.jms.JmsComponent;
> import org.apache.camel.component.jms.JmsMessageType;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.spring.SpringCamelContext;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.junit.Assert;
> import org.junit.Before;
> import org.springframework.context.support.GenericApplicationContext;
>
>
> public class JMSReplyToTest extends CamelTestSupport {
>
>    private ActiveMQConnectionFactory factory;
>    private SpringCamelContext camelContext;
>
>    @EndpointInject(uri = "mock:result")
>    protected MockEndpoint resultEndpoint;
>
>    @Produce(uri = "direct:start")
>    protected ProducerTemplate template;
>
>    @Before
>    public void setUp() throws Exception {
>
>        factory = new ActiveMQConnectionFactory("vm://local");
>        super.setUp();
>    }
>
>
>    @org.junit.Test
>    public void test() throws Exception {
>        template.sendBody("test");
>        resultEndpoint.expectedMessageCount(1);
>
> Assert.assertTrue(resultEndpoint.getExchanges().get(0).getIn().getHeader("test")
> != null);
>
> Assert.assertTrue(resultEndpoint.getExchanges().get(0).getIn().getHeader("test").equals("test"));
>
> Assert.assertTrue(resultEndpoint.getExchanges().get(0).getIn().getHeader("JMSReplyTo")
> != null);
>
> Assert.assertTrue(resultEndpoint.getExchanges().get(0).getIn().getHeader("JMSReplyTo").equals("SYSTEM.SOAP.RESPONSE.QUEUE"));
>        resultEndpoint.assertIsSatisfied();
>    }
>
>    @Override
>    protected CamelContext createCamelContext() throws Exception {
>        GenericApplicationContext applicationContext = new
> GenericApplicationContext();
>        camelContext = new SpringCamelContext(applicationContext);
>        JmsComponent jmsComponent = new JmsComponent();
>        jmsComponent.setConnectionFactory(factory);
>        applicationContext.getBeanFactory().registerSingleton("jms",
> jmsComponent);
>        return camelContext;
>    }
>
>    @Override
>    protected RouteBuilder createRouteBuilder() {
>        return new RouteBuilder() {
>            public void configure() {
>                from("direct:start").setHeader("JMSReplyTo",
> constant("queue:SYSTEM.SOAP.RESPONSE.QUEUE")).setHeader("test",
> constant("test")).to("jms:result?replyTo=queue://SYSTEM.SOAP.RESPONSE.QUEUE");
>                from("jms:result").to("mock:result");
>            }
>        };
>    }
>
>
> }
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Setting-JMS-ReplyTo-tp2800345p2800345.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