In the Publish and Subscribe (Pub/Sub) messaging model, one client application can send a message to many other client applications. In the Pub/Sub model, a message producer is a publisher and a consumer is a subscriber .
This illustration shows three subscribers who have each received message A and are about to receive message B, and then message C:
Client application 1, a synchronous subscriber, waits for a message, for a specified time or forever, and then blocks to receive again after processing a message.
Client application 2, a durable subscriber specified an interest in receiving messages from the broker on the selected topic, even when disconnected. Messages are saved for durable subscribers, although a saved message can expire while waiting for the durable subscriber to reconnect.
Client application 3, an asynchronous subscriber has set up a message listener. When a message arrives, the
onMessagemethod in the client is called. Although it is not shown in the illustration, this subscriber has a message selector. The subscriber provided a string in SQL syntax as a parameter when the subscription was created. If the selection criteria are not met, the subscriber does not take delivery of that message.
The following illustration shows the distribution of message delivery. The shapes on the publisher lines indicate messages published to specific topics over time. The crossovers within the broker represent the subscriptions that could have wildcard patterns so a single subscription delivers messages from many topics. The shapes on the subscriber lines indicate that everyone subscribed to a topic receives the same message at the same time. The exception is the durable subscription that, when not active, can receive its messages later, provided the messages do not expire.
There are several special techniques for registering a durable interest and to distribute the load of subscribed messages but they all involve the notion of a subscription: if your consumer (or registered interest) is there when the message arrives on the topic, you and everyone else there gets that message. If you missed it (and did not register a durable interest), it is gone.
Any messages that are not acknowledged by durable subscribers when they are not connected to the broker, are preserved by the broker and redelivered when the durable subscriber reconnects. When a durable subscriber reconnects, messages are delivered in the correct order, although some messages might have expired. If a durable subscriber does not acknowledge delivery of a message, the message is retained until it expires.










