简体   繁体   English

骆驼作为JMS客户端

[英]Camel as a JMS client

I am working on a client/server request/reply system using Camel. 我正在使用Camel开发客户端/服务器请求/回复系统。

The client and server communicate using two JMS queues: request queue and response queue. 客户端和服务器使用两个JMS队列进行通信:请求队列和响应队列。

The server side has a camel route which consumes the JMS message from the request queue and process message concurrently. 服务器端具有骆驼路由,该骆驼路由消耗来自请求队列的JMS消息并同时处理消息。 The response is sent back to the client using the response queue. 使用响应队列将响应发送回客户端。

The client side sends a message to the JMS queue and wait for the response. 客户端将消息发送到JMS队列,然后等待响应。 I have two questions: 我有两个问题:

  1. The client side is actually a library that will be used by other application. 客户端实际上是一个将由其他应用程序使用的库。 I want to use Camel on the client side as well but don't know how to use Camel as a "function" ie At some point in my have code, I need to do "send this object to this camel route". 我也想在客户端使用Camel,但不知道如何将Camel用作“函数”,即在我拥有代码的某个时候,我需要做“将该对象发送到此骆驼路线”。 How can I do this? 我怎样才能做到这一点?

  2. Is there a standard way for camel to handle the request/reply using two queues? 骆驼是否有使用两个队列处理请求/答复的标准方法?

Thank you very much. 非常感谢你。

  1. Use the ProducerTemplate from the CamelContext. 使用CamelContext中的ProducerTemplate It requires you to keep a camel context around in the client somewhere. 它要求您在客户端的某个地方保持驼峰环境。

    You can do stuff like: producerTemplate.requestBody(myPayload,"jms:queue:whatever"); 您可以执行以下操作: producerTemplate.requestBody(myPayload,"jms:queue:whatever");

  2. Camel can handle request reply using several different ways . 骆驼可以使用几种不同的方式处理请求回复。 Using an explicit reply queue (no temporary queues, which are used by default), you can either use exclusive mode, which is faster: jms:queue:request.queue?replyTo=client1.replies&replyToType=Exclusive but requires a unique queue per client. 使用显式答复队列(默认情况下不使用临时队列),您可以使用更快的独占模式: jms:queue:request.queue?replyTo=client1.replies&replyToType=Exclusive但每个客户端需要唯一的队列。 The other alternative is a shared queue for all clients. 另一种选择是为所有客户端共享队列。 The URI looks like this: activemq:queue:request.queue?replyTo=shared.replies . URI如下所示: activemq:queue:request.queue?replyTo=shared.replies Please note: a shared reply queue will use JMS selectors to pick messages for each client, and that will cost you performance and round trip latency. 请注意:共享回复队列将使用JMS选择器为每个客户端选择消息,这将降低性能和往返延迟。

For question 1, you can use the camel producer template option which can invoke a camel route. 对于问题1,可以使用可以调用骆驼路线的骆驼生产者模板选项。 Answer for question 2 is yes, you can refer to http://camel.apache.org/request-reply.html 问题2的答案是肯定的,您可以参考http://camel.apache.org/request-reply.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM