如何使一个JMS同步请求 [英] How to make a JMS Synchronous request

查看:183
本文介绍了如何使一个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.

推荐答案

首先,打开响应队列。然后通过该对象设置回复到方法上的消息。这样的服务响应您的要求知道哪里来发送回复。通常情况下,服务将消息ID复制到相关ID字段,这样,当你发送邮件,带你找回消息ID和使用的的监听的应答队列。当然,如果你使用动态回复,甚至排队,是不是neessary - 只听队列上的下一条消息

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.

有样品code,显示了这一切。如果安装到默认位置,样品code住在C:\\ Program Files文件(x86)的\\ IBM \\ WebSphere MQ的\\工具\\ JMS \\ SAMPLES \\简单\\ SimpleRequestor.java上一个* nix中框Windows中或 /var/mqm/tool​​sjms/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天全站免登陆