Is synchronous messaging possible with JMS / WMQ?

Let's say there is a mobile application that must complete a synchronization request / request for some data from the server. First, the request will be sent to host the JMS client, which will publish the message / request on the external queue (from the partner). Now that it starts obscure. How to get a response from a partner in a synchronous way.

  • If a partner sets up a separate queue for me to subscribe, and then I block my mobile phone request until I receive a response message from this separate queue?
  • Does JMS or the native WebSphere MQ interface support message synchronization?
  • What are other ways to implement it when messaging?

thanks

+4
source share
3 answers

A sample tutorial is as follows:

  • The JMS application receives a request from a mobile device.
  • The JMS application opens a response queue (which can be dynamic).
  • The JMS application prepares a message indicating the destination from # 2 as the JMSREplyTo address.
  • The JMS application sends a request outside the synchronization point to an external service provider.
  • The JMS application listens for a response with a specified wait interval. If he used a dynamic response queue, he performs a simple reception. If multiple instances are listening on the same queue (which is more likely with an external service), then it uses the JMSMessageID returned from send as the JMSCorrelationID specified in the receive.
  • The JMS application receives a response from an external service.
  • The JMS application is responding to a mobile device.

Note that using WMQ, the expected behavior of the service provider is to copy the JMSMessageID from the request message to the JMSCorrelationID of the response. Less often, the sender needs to generate a JMSCorrelation identifier and copy it into the JMSCorrelationID of the response, but some applications use this behavior. You will need to understand how your service provider handles this to determine the correct behavior of your requester application.

If you use the full installation of the WMQ client, you will already have sample code that will execute most of this. If it is installed by default, look ...

C:\Program Files\IBM\Websphere MQ\tools\jms\samples\simple\simpleRequestor.java

... or an equivalent location in the /var/mqm for UNIX / Linux distributions. This is one of many reasons to install a full client, and not just capture jar files. If you need to download the client, it comes as SupportPac MQC7 .

+4
source

The "client" can create a temporary queue and pass the name of this in the request.

The "server" receives the request in a known queue, but sends a "replyTo" with the name of the queue specified by the "client".

JMS has the "replyTo" property for this purpose.

Thus, the client sees only messages intended for him.

+2
source

At the top of my head, I see two ways.

  • create 2 queues: incoming and outgoing. The client sends to the inbound queue and receives messages from the outbound queue.

  • you can use the same queue for both. Just set a special property for each message and use the selector to filter only the relevant messages.

your server side should first send a message and then call the receive method (see JMS javadoc). This method is blocked until you receive a message or timeout. It is important for you to use this method and not listen to messages (listeners are used for asynchronous mode)

0
source

Source: https://habr.com/ru/post/1340194/


All Articles