Writing subscriber applications
Get started with writing subscriber applications by studying three examples: an IBM MQ application consuming messages from a queue, an application that creates a subscription and requires no knowledge of queuing, and finally an example that uses both queuing and subscriptions.
In Table 1 the three styles of consumer or subscriber are listed, together with the sequences of IBM MQ function calls that characterize them.- The first style, MQ Publication Consumer, is identical to a point to point MQ program that only does MQGET. The application has no knowledge that it is consuming publications - it is simply reading messages from a queue. The subscription that causes publications to get routed to the queue is created administratively using IBM MQ Explorer or a command.
- The second style is the preferred pattern for most subscriber applications. The subscriber application creates the subscription, and then gets publications. The queue management is all performed by the queue manager. This is known as a managed subscriber.
- In the third style, the subscriber application is responsible for specifying the queue that will be used to hold publications, opening and closing that queue and issuing subscriptions to fill the queue with publications. This is known as an unmanaged subscriber.
One way to understand these styles is to study the example C programs listed in Table 1 for each of the styles. The examples are designed to be run in conjunction with the publisher example found in Writing publisher applications.
Step | MQ message consumer | Example 1: MQ Publication consumer | Example 2: Managed MQ subscriber | Example 3: Unmanaged MQ subscriber |
---|---|---|---|---|
Connect to a queue manager | MQCONN | MQCONN | MQCONN | MQCONN |
Open queue | MQOPEN | MQOPEN | MQOPEN | |
Subscribe | MQSUB | MQSUB | ||
Get message(s) | MQGET | MQGET | MQGET | MQGET |
Close queue | MQCLOSE | MQCLOSE | (MQCLOSE) | MQCLOSE |
Close subscription | MQCLOSE | MQCLOSE | ||
Disconnect from queue manager | MQDISC | MQDISC | MQDISC | MQDISC |
Another way to understand publish/subscribe application patterns is too look at the interactions between the different entities involved. Lifeline, or UML sequence diagrams are a good way to study interactions. Three lifeline examples are described in Publish/subscribe lifecycles.
- Example 1: MQ Publication consumer
The MQ Publication consumer is an IBM MQ message consumer that does not subscribe to topics itself. - Example 2: Managed MQ subscriber
The managed MQ subscriber is the preferred pattern for most subscriber applications. The example requires no administrative definition of queues, topics or subscriptions. - Example 3: Unmanaged MQ subscriber
The unmanaged subscriber is an important class of subscriber application. With it, you combine the benefits of publish/subscribe with control of queuing and consumption of publications. The example demonstrates different ways of combining subscriptions and queues.
Parent topic: Writing publish/subscribe applications