Search code examples
javajmsmessagingibm-mqmq

Synchronous messaging possible with JMS/WMQ?


Let's say there is a mobile application that needs to make a sync request/query for some data from a server. The request will come to hosted JMS client first, that will publish a message/request on external Queue (from partner). Now here where it start to be unclear. How do I get a response back from the partner in the synchronous fashion.

  • Should the partner expose separate queue for me to subscribe and I then block the mobile request till I get the response message from that separate queue?
  • Does JMS or proprietary WebSphere MQ interface have support for sync messaging?
  • What are other ways to implement it with messaging?

Thanks


Solution

  • The textbook pattern is as follows:

    1. JMS app receives a request from the mobile device.
    2. JMS app opens the reply-to queue (which may be dynamic).
    3. JMS app prepares a request message specifying the destination from #2 as the JMSREplyTo destination.
    4. JMS app sends the request outside of syncpoint to the external service provider.
    5. JMS app listens for a response with a specified wait interval. If it used a dynamic reply-to queue it does a simple receive. If multiple instances are listening on the same queue (which is more likely with an external service) then it uses the JMSMessageID returned from the send as the JMSCorrelationID specified on the receive.
    6. JMS app receives the response from the external service.
    7. JMS app replies to the mobile device.

    Note that with WMQ the expected behavior from the service provider is to copy the JMSMessageID from the request message to the JMSCorrelationID of the response. It is less common to require the sender to generate a JMSCorrelation ID and copy it to the JMSCorrelationID of the response but some applications use that behavior. You will need to understand how your service provider deals with this to determine the correct behavior for your requester application.

    If you are using the complete WMQ Client install you will already have sample code that does most of this. If installed to the default location, look in...

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

    ...or the equivalent location under /var/mqm for UNIX/Linux distributions. This is one of the many reasons to install the full client rather than simply grabbing the jar files. If you need to download the client is is delivered as SupportPac MQC7.