+

Search Tips | Advanced Search

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 the application processes only messages for one subscription then, as a minimum, we 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.

  • Managed queues and publish/subscribe
    When creating a subscription we can choose to use managed queuing. If we use managed queuing a subscription queue is automatically created when you create a subscription. Managed queues are tidied up automatically in accordance with the durability of the subscription. Using managed queues means that we do not have to worry about creating queues to receive publications and any unconsumed publications are removed from subscriber queues automatically if a non-durable subscription connection is closed.
  • Subscription durability
    Subscriptions can be configured to be durable or non-durable. Subscription durability determines what happens to subscriptions when subscribing applications disconnect from a queue manager.
  • Selection strings
    A selection string is an expression that is applied to a publication to determine whether it matches a subscription. Selection strings can include wildcard characters.

Parent topic: Publish/subscribe components


Related information

Last updated: 2020-10-04