从豆骆驼响应返回到ActiveMQ的队列 [英] Camel response from bean back onto ActiveMQ queue
问题描述
我用骆驼(与骆驼EJB依赖)从ActiveMQ的我bean的方法来路由消息。到目前为止,我已经得到了它在我的requestHandler豆收到消息。
< AMQ:connectionFactory的ID =amqConnectionFactory
brokerURL =TCP://本地主机:61616/>< bean类=org.springframework.jms.connection.CachingConnectionFactory
ID =connectionFactory的>
<构造带参数REF =amqConnectionFactory/>
<属性名=sessionCacheSizeVALUE =100/>
< /豆>< bean类=org.springframework.jms.core.JmsTemplateID =JmsTemplate的>
<构造带参数REF =的connectionFactory/>
< /豆><骆驼:camelContext ID =camelContext>
<骆驼:路线>
<骆驼:从URI =的ActiveMQ:队列:INQUEUE/>
<骆驼:setExchangePattern模式=的InOut/>
<骆驼:到URI =豆:requestHandler方法=的handleRequest/>
< /骆驼:路线>
< /骆驼:camelContext>
如果我改变现在的handleRequest返回一个字符串,我将如何修改我的路线把字符串队列后面的人给我留言?
谢谢!
编辑:
客户端code:
(骆驼-context.xml中)
<骆驼:camelContext ID =骆驼客户>
<骆驼:模板ID =camelTemplate/>
< /骆驼:camelContext><豆的id =JMS级=org.apache.activemq.camel.component.ActiveMQComponent>
<属性名=brokerURLVALUE =TCP://本地主机:61616/>
< /豆>
(在CamelClient.java)
公共类CamelClient {
公共静态无效的主要(字串[] args){ ApplicationContext的情况下=新的ClassPathXmlApplicationContext(骆驼的context.xml);
ProducerTemplate pTemplate = context.getBean(camelTemplate,ProducerTemplate.class); 的System.out.println(消息发送启动);
字符串RET = pTemplate.requestBody(ActiveMQ的:队列:INQUEUE,47264,为String.class);
的System.out.println(收到的消息:+ RET);
}
}
和尝试添加在路由日志步
<骆驼:路线>
<骆驼:从URI =的ActiveMQ:队列:INQUEUE/>
<骆驼:setExchangePattern模式=的InOut/>
<骆驼:到URI =豆:requestHandler方法=的handleRequest/>
<骆驼:到URI =日志:回复/>
< /骆驼:路线>
和还向我们展示了code为您requestHandler豆做什么的,可以让我们帮助你更好的。
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.
这篇关于从豆骆驼响应返回到ActiveMQ的队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!