camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Bouer <ericbo...@gmail.com>
Subject Still problems with InOut JMS
Date Mon, 06 Jul 2009 22:15:33 GMT

I finally had time to try again the JMSReplyTo issue.
Going back to  https://issues.apache.org/activemq/browse/CAMEL-1773
https://issues.apache.org/activemq/browse/CAMEL-1773 .
I understand that I can set JMSReplyTo header of InOnly message and also
send it with preserveMessageQos=true. but then camel won't really wait for a
response(i.e won't get an exception when a timeout occures)
I do want camel to correlate JMS messages and wait for reply but I want to
have control on the JMSReplyTo.
Can I set the JMSReplyTo of a route that has InOut pattern ?
It seems to ignore everything I try.
I'm providing a test case that goes like this:
A non-camel JMS client  says "Hello I'm here" which is InOnly message.
(Advisory in real app)
The server asks  "What's your name?" which is InOut Message, the non-camel
client should reply it's name.
I want to get the reply "my name is .." in specific queue and not the temp
one camel creates by default.
I'm not using JmsTemplate to send the request on purpose.
Thanks again.
Eric.

============ Test Code ========
package org.apache.camel.component.jms;


import javax.jms.Destination;
import javax.jms.TextMessage;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.CamelTestSupport;

import org.springframework.jms.core.JmsTemplate;
import static
org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;

public class JmsCustomJMSReplyToInOutTest extends CamelTestSupport {

    private ActiveMQComponent amq;
    private static String MQURI =
"vm://localhost?broker.persistent=false&broker.useJmx=false";
//    private static String MQURI = "tcp://amq1:61616";

    public void testCustomJMSReplyToInOut() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceived("My name is Arnio");
        // start a inOnly route
        template.sendBody("activemq:queue:hello", "Hello, I'm here");
//Advisory
        // now consume using something that is not Camel
        Thread.sleep(1000);

        JmsTemplate jms = new
JmsTemplate(amq.getConfiguration().getConnectionFactory());
        TextMessage msg = (TextMessage) jms.receive("nameRequestor");
        assertEquals("What's your name", msg.getText());
        // there should be a JMSReplyTo so we know where to send the reply
        Destination replyTo = msg.getJMSReplyTo();
        System.out.println("Reply will be sent to " + replyTo.toString());
        assertEquals("queue://nameReplyQueue", replyTo.toString());
        // send reply
        template.sendBody("activemq:" + replyTo.toString(), "My name is
Arnio");
        Thread.sleep(2000);
        assertMockEndpointsSatisfied();
    }

 
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {

            public void configure() throws Exception {
                from("activemq:queue:hello")
                        .inOut()
                        .process(new Processor() {
                        public void process(Exchange exchange) throws
Exception {
                            exchange.getIn().setHeader("JMSReplyTo",
"nameReplyQueue");
                            exchange.getOut().setBody("What's your name");
                            exchange.getOut().setHeader("JMSReplyTo",
"nameReplyQueue"); //this should be enough
                            }
                        })
                        .setHeader("JMSReplyTo",constant("nameReplyQueue"))
// maybe this ?
                       
.setProperty("JMSReplyTo",constant("nameReplyQueue")) // or this ?
                       
.to("activemq:queue:nameRequestor?preserveMessageQos=true");
                        //this will force JMSReplyTo but won't correlate
later.
                       
//.to("activemq:queue:nameRequestor?replyTo=queue:nameReplyQueue");

                from("activemq:queue:nameReplyQueue").to("mock:result");
            }
        };
    }
   protected CamelContext createCamelContext() throws Exception {
        CamelContext camelContext = super.createCamelContext();
        amq = activeMQComponent(MQURI);
        camelContext.addComponent("activemq", amq);
        return camelContext;
    }
}


-- 
View this message in context: http://www.nabble.com/Still-problems-with-InOut-JMS-tp24363764p24363764.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Mime
View raw message