Configure AMQP clients to interact directly with applications on IBM MQ queues

The IBM MQ AMQP implementation supports publish/subscribe only. AMQP clients cannot put messages to, or get messages from, IBM MQ queues directly. In order to allow publishing AMQP clients to send messages to an existing queue, or subscribing AMQP clients to receive messages that were put to a queue, create some additional objects.


Overview

For example, assume there is an application getting messages from an input queue IN_QUEUE and putting those messages to an output queue OUT_QUEUE. It is possible for AMQP clients to put messages to IN_QUEUE, and get messages from OUT_QUEUENote: There are no changes required to the application itself.

For an AMQP publisher to put a message to a queue, we need to create an administrative subscription for the topic string the AMQP client is publishing to, with a destination of the intended queue; see Send messages to the application:.

For an AMQP subscriber to get messages from a queue, we need to replace the queue with an alias queue of the same name, with a target of a topic object representing the topic string the AMQP client is subscribed to; see Getting messages from the application:


Send messages to the application:

The application is already picking up messages from IN_QUEUE and we want an AMQP client to be able to publish messages, so that they go to this queue to be processed by the application.

To do this, you create a new administrative subscription, where the topic string this subscription receives messages from, is the topic string that the AMQP client publishes to. The destination queue of this subscription is the input queue for the application, IN_QUEUE.

Any messages that are published to the defined topic string for that administrative subscription are routed to the defined destination, in this case IN_QUEUE.

Assuming the AMQP client publishes to a topic string /application/in, we can create an administrative subscription APP_IN, using the following MQSC command:
DEF SUB(APP_IN) TOPICSTR('/application/in') DEST('IN_QUEUE')
When you have defined this object, all messages published to /application/in are routed to the destination IN_QUEUE, where they are picked up by the application in the same way as any other messages put to this queue by other applications.


Getting messages from the application:

The application is putting messages to OUT_QUEUE, where they can be picked up and processed by other clients.

However, in this case, we want the messages to be delivered to an AMQP client instead, but AMQP clients only use publish/subscribe, and cannot pick messages up directly from a queue.

To replace the clients previously receiving message with the subscribing AMQP client, we need to create a topic object, for the topic string that the AMQP client is subscribed to, and an alias queue.Attention: If you define the alias queue, and then start the producing application before any AMQP clients have had a chance to subscribe, messages the producing application sends to the "queue" (now a topic) will be lost because there are no subscribers.

The changes described in this text, replace the clients previously receiving messages with the subscribing AMQP client only. To use a combination of AMQP and other clients to get messages, more extensive changes are required.

Assuming the AMQP client subscribes to a topic string /application/out, we can define the topic object APP_OUT using the following MQSC command:
DEF TOPIC(APP_OUT) TOPICSTR('/application/out')

Any messages delivered to this topic object are delivered to the AMQP client subscribing to the same topic string.

You then need to ensure that messages put to OUT_QUEUE by the application are delivered to this new topic object, so that they are sent to the subscribing client.

To do this, replace the existing queue OUT_QUEUE with an alias queue of the same name, with a target type of the topic object just created, using the following MQSC command:
DEF QALIAS(OUT_QUEUE) TARGTYPE(TOPIC) TARGET(APP_OUT)

Now, messages put by the application to OUT_QUEUE do not wait on the queue to be picked up; instead they are delivered to the target of this alias queue, that is, the new topic object APP_OUT.

The AMQP client, which is subscribed to the topic string represented by this topic object /application/out, then receives any messages sent to this topic object from the alias queue.

Parent topic: Topologies for AMQP clients with IBM MQ


Related information