Subscribers and subscriptions

In IBM® MQ publish/subscribe, a subscriber is an application that requests information about a specific topic from a queue manager in a publish/subscribe network. A subscriber can receive messages, about the same or different topics, from more than one publisher.

Subscriptions can be created manually using an MQSC command or by applications. These subscriptions are issued to the local queue manager and contain information about the publications the subscriber wants to receive:
  • The topic the subscriber is interested in; this can resolve to multiple topics if wildcards are used.
  • An optional selection string to be applied to published messages.
  • A handle to a queue (known as the subscriber queue ), on which selected publications should be placed, and the optional CorrelId.
The local queue manager stores subscription information and when it receives a publication, scans the information to determine whether there is a subscription that matches the publication's topic and selection string. For each matching subscription, the queue manager directs the publication to the subscriber's subscriber queue. The information that a queue manager stores about subscriptions can be viewed by using the DIS SUB and DIS SBSTATUS commands.
A subscription is deleted only when one of the following events occurs:
  • The subscriber unsubscribes using the MQCLOSE call (if the subscription was made non-durably).
  • The subscription expires.
  • The subscription is deleted by the system administrator using the DELETE SUB command.
  • The subscriber application ends (if the subscription was made non-durably).
  • The queue manager is stopped or restarted (if the subscription was made non-durably).

When getting messages, use appropriate options on the MQGET call. If your application processes only messages for one subscription then, as a minimum, you should use get-by-correlid, as demonstrated in the C sample program amqssbxa.c and at unmanaged MQ subscriber. The CorrelId to use is returned from MQSUB in the MQSD.SubCorrelId field.