如何发出 JMS 同步请求 [英] How to make a JMS Synchronous request

查看:23
本文介绍了如何发出 JMS 同步请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 web 应用程序,它应该从一个只能通过消息传递 (JMS) 访问的外部应用程序中获取和显示数据.

I have an webapp that is expected to fetch and display data from an External App which is accessible only via messaging (JMS).

因此,如果用户在浏览器上提交请求,则同一个 HTTP 请求线程必须与消息传递系统(MQ 系列)交互,以便同一个请求线程可以显示从消息传递系统接收到的数据.

So, if a user submits a request on a browser, the same HTTP request thread will have to interact with the Messaging system (MQ Series) such that the same request thread can display the data received from the Messaging System.

这里有我可以使用的模式吗?我在网上看到一些模糊的参考,以这种方式使用相关 ID":

Is there a pattern I can make use of here? I saw some vague references on the net that use "Correlation ID" in this way:

Msg m = new TextMsg("findDataXYZ");
String cr_id = m.setCorrelationID(id);

sendQueue.send(m).

// now start listening to the Queue for a msg that bears that specific cr_id

Response r = receiverQueue.receive(cr_id);

那里有更好的东西吗?我发现的其他模式期望异步接收响应......这对我来说不是一个选择,因为我必须在同一个 HTTP 请求上发送响应.

Is there something better out there? The other patterns I found expect the response to be received asynchronously.. which is not an option for me, since I have to send the response back on the same HTTP request.

推荐答案

首先,打开响应队列.然后将该对象传递给消息上的 set 回复方法.这样,响应您请求的服务就知道将回复发送到哪里.通常,该服务会将消息 ID 复制到相关 ID 字段,因此当您发送消息时,获取返回的消息 ID 并使用那个来侦听回复队列.当然,如果您使用动态回复队列,即使这不是必需的 - 只需侦听队列中的下一条消息.

First, open the response queue. Then pass that object to the set reply-to method on the message. That way the service responding to your request knows where to send the reply. Typically the service will copy the message ID to the correlation ID field so when you send the message, take the message ID you get back and use that to listen on the reply queue. Of course if you use a dynamic reply-to queue even that isn't neessary - just listen for the next message on the queue.

有显示所有这些的示例代码.如果您安装到默认位置,则示例代码位于 Windows 上的 "C:\Program Files (x86)\IBM\WebSphere MQ\tools\jms\samples\simple\SimpleRequestor.java"框或 *nix 框上的 /var/mqm/toolsjms/samples/simple/SimpleRequestor.java.

There's sample code that shows all of this. If you installed to the default location, the sample code lives at "C:\Program Files (x86)\IBM\WebSphere MQ\tools\jms\samples\simple\SimpleRequestor.java" on a Windows box or /var/mqm/toolsjms/samples/simple/SimpleRequestor.java on a *nix box.

如果您想知道安装什么,究竟是什么?"WMQ 客户端安装可作为 SupportPac MQC71 免费下载.

And on the off chance you are wondering "install what, exactly?" the WMQ client install is downloadable for free as SupportPac MQC71.

这篇关于如何发出 JMS 同步请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆