문제

I'm using Camel (with the camel-ejb dependency) to route messages from an ActiveMQ to my bean's method. So far I've got it receiving the message in my requestHandler bean.

<amq:connectionFactory id="amqConnectionFactory"
    brokerURL="tcp://localhost:61616" />

<bean class="org.springframework.jms.connection.CachingConnectionFactory"
    id="connectionFactory">
    <constructor-arg ref="amqConnectionFactory" />
    <property name="sessionCacheSize" value="100" />
</bean>

<bean class="org.springframework.jms.core.JmsTemplate" id="jmsTemplate">
    <constructor-arg ref="connectionFactory" />
</bean>

<camel:camelContext id="camelContext">
    <camel:route>
        <camel:from uri="activemq:queue:inQueue" />
        <camel:setExchangePattern pattern="InOut"/>
        <camel:to uri="bean:requestHandler?method=handleRequest" />
    </camel:route>
</camel:camelContext>

If I now change handleRequest to return a String, how would I modify my route to put the String on the queue back to the person sending me a message?

Thanks!

EDIT:

Client code:

(in camel-context.xml)

<camel:camelContext id="camel-client">
    <camel:template id="camelTemplate" />
</camel:camelContext>

<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://localhost:61616" />
</bean>

(in CamelClient.java)

public class CamelClient  {
    public static void main(String[] args) {

        ApplicationContext context = new ClassPathXmlApplicationContext("camel-context.xml");
        ProducerTemplate pTemplate = context.getBean("camelTemplate", ProducerTemplate.class);

        System.out.println("Message Sending started");
        String ret = pTemplate.requestBody("activemq:queue:inQueue", "47264", String.class);
        System.out.println("Message received:" + ret);
    }
}
도움이 되었습니까?

해결책

And try adding a log step in the route

<camel:route>
    <camel:from uri="activemq:queue:inQueue" />
    <camel:setExchangePattern pattern="InOut"/>
    <camel:to uri="bean:requestHandler?method=handleRequest" />
    <camel:to uri="log:reply" />
</camel:route>

And also show us the code for your requestHandler bean what it does, can let us help you better.

다른 팁

This happens out of the box. If the JMS message has a JMSReplyTo header then Camel sends back a reply message, when the routing is complete. So in your bean, just return what you want to send back.

So if you method is

public String handleRequest(String input) {
   return "Hello " + input;
}

Then you will send back a String with hello < original body here >

I suggest to spend a bit time reading this page

as JMS and camel-jms has many options, so take a bit time to learn more about it.

You must force the exchange pattern to be inout: jms:MyQueue?exchangePattern=InOut

More info on the camel docs: http://camel.apache.org/request-reply.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top