Pub/Sub Event Notifications
In multiple clients connected to cache environment, the best way to communicate among them is important. Events is an efficient mechanism in Pub/Sub to notify the publisher and subscriber about various events happening across the cache and applications.
Message Delivery Failure Notification
MessageDeliveryFailure fires events on topic so that publisher receives all failed messages that are not delivered to any subscribers or may be messages are expired or evicted before delivery.
Delivery failure notification is raised to any publisher which has registered message failure event on that topic.
If message fails to deliver e.g. message is not received by subscriber due to any error, it retries until message expiration.
If message expiration is triggered, a notification is sent to publisher containing the expired message and failure reason.
If messages are marked as failed, the messages are only sent to publisher.
If there is no subscription against the topic, messages are removed from the topic.
If the publisher has not registered for failure events, the messages are removed from the topic.
In case a message has been published with no expiration, no notification will be sent as the message stays within the topic indefinitely until the cache is active.
Message Received Notification
MessageReceivedCallback fires event to registered subscriber against the topic so that it can receive the published messages.
Subscribers register a
MessageReceivedCallback
against the topic.Messages are received by subscriber(s) asynchronously. Subscribers register the event against the topic showing interest for messages. When a message is published on the topic, the topic sends these messages to subscriber(s).
Topic Deletion Notification
In case a topic is deleted, it is a forceful deletion and deletes all messages and related meta-info form the cache. Hence, the subscriber and publisher must be notified of this deletion because of the following reasons:
The subscriber might be waiting for incoming messages from the registered topic. Once the topic does not exist, the subscribers can then handle their execution accordingly through event notification and prevent infinite waiting state.
The publisher can prevent sending messages to a non-existing topic and handle any pending payloads and future execution accordingly.
Additional Resources
NCache provides sample application for Pub/Sub on GitHub.
See Also
Event Notifications in Cache
Pub/Sub Topics
Public Messages to Topic
Subscribe for Topic Messages
Continuous Query