简体   繁体   English

使用JMS作为请求/响应服务

[英]Using JMS as a request/response service

There are various implementations for using JMS as a request/response service. 使用JMS作为请求/响应服务有各种实现。 I would like to know the ideal implementation. 我想知道理想的实现。 Below are these various implementations. 以下是这些不同的实现。


1) Permanent request queue, Dynamic response queue 1)永久请求队列,动态响应队列

All request messages are published into a single request queue specifying the reply queue. 所有请求消息都发布到指定回复队列的单个请求队列中。 The service consumes the request message and publishes a message back onto a dynamic reply queue. 该服务使用请求消息并将消息发布回动态回复队列。

  • No need for a correlation id. 不需要相关ID。
  • Multiple consumers of their corresponding response queues 其相应响应队列的多个消费者

2) Permanent request queue, Permanent response queue 2)永久请求队列,永久响应队列

All request message are published into a single request queue, specifying a unique id in the jms properties. 所有请求消息都发布到单个请求队列中,在jms属性中指定唯一ID。 Unique id is stored locally. 唯一ID存储在本地。 Service consumes request message and publishes message back onto response queue. 服务使用请求消息并将消息发布回响应队列。 A single response consumer will consume the message and act appropriately based on the unique id. 单个响应使用者将使用该消息并根据唯一ID进行适当操作。

  • Correlation id required. 需要相关ID。
  • Single consumer of the response queue 响应队列的单个使用者

3) Permanent request queue, Permanent response topic 3)永久请求队列,永久响应主题

All request messages are published into a single request queue, specifying a unique id in the jms properties. 所有请求消息都发布到单个请求队列中,在jms属性中指定唯一ID。 The service consumes the request message and publishes a message with the same unique id in the jms properties back onto the topic. 该服务使用请求消息,并在jms属性中将具有相同唯一ID的消息发布回主题。 Consumers of the response will set a message selector to select for only the message the contains the unique id. 响应的使用者将设置消息选择器以仅选择包含唯一ID的消息。

  • Correlation id required. 需要相关ID。
  • Multiple consumers of the response topic 响应主题的多个消费者

Does anyone know other implementations? 有谁知道其他实现? And which of these implementations is the ideal solution for using JMS as a request/response service? 哪些实现是使用JMS作为请求/响应服务的理想解决方案?

This is what I usually do: Request posted to the 'permanent', 'well-known' queue. 这就是我通常所做的:请求发布到'永久','众所周知'队列。 In the request message sender specifies replyTo queue which can be permanent or dynamic depending on your app. 在请求消息中,sender指定replyTo队列,该队列可以是永久性的或动态的,具体取决于您的应用程序 requirement. 需求。

Reasonably unique id/correlation id should always be used at least for traceability of the messages in the log files etc. It could be on JMS headers level or on payload level (eg SOAP messageId) depending on your requirements. 应始终至少使用合理唯一的id / correlation id来跟踪日志文件中的消息的可跟踪性。它可能位于JMS头级别或有效负载级别(例如SOAP messageId),具体取决于您的要求。

I have used both first and third implementations. 我已经使用了第一个和第三个实现。 I am not sure about the second one as single queue for multiple consumers can cause issue when one consumer can starve another consumers. 我不确定第二个,因为当一个消费者可能饿死另一个消费者时,多个消费者的单个队列会引起问题。 To avoid that, we might need to have a dispatcher in place which again can lead to scalability issue as new queue will need to be added for each consumer. 为避免这种情况,我们可能需要有一个调度程序 ,这可能导致可伸缩性问题,因为需要为每个使用者添加新队列。

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

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