Pub/Sub Event Notifications
If multiple clients are connected in a cache environment, there needs to be effective communication among them. Event Notifications 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 notification is registered by the publisher against a topic. This failure notification along with the failed message is sent to the publisher when a message fails to deliver to the subscriber or if the message is evicted or expired before delivery.
Delivery failure notification is sent to any publisher that has registered a message failure event on a topic.
If a message fails to deliver due to any error, the topic retries to deliver that message until the message is expired or evicted.
If message expiration is triggered, a notification is sent to the publisher containing the expired message and failure reason.
If messages are marked as failed, the messages are only sent to the publisher.
In case a message has been published to a topic without any expiration configured, no notification will be sent to the publisher as the message stays within the topic till the cache is active.
If you have disabled eviction and haven't set an expiry on your messages, your messages will persist on the cache, and the cache can become full. When the cache becomes full it won't take any further requests, and future messages will fail to deliver. In this case, a delivery failure notification will also be triggered and sent to the publisher that has registered itself for that said notification.
Message Received Notification
MessageReceivedCallback fires events to registered subscribers against the topic so that it can receive the published messages.
Subscribers register a MessageReceivedCallback against the topic.
Messages are received by the subscriber(s) asynchronously. Subscribers register the event against the topic showing interest in the messages. When a message is published on the topic, it delivers this message to the subscriber(s).
Topic Deletion Notification
In case a topic is deleted, it deletes all messages and related meta-info from 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 an infinite waiting state.
The publisher can prevent sending messages to a non-existing topic and handle any pending payloads and future execution accordingly.
NCache provides a sample application for Pub/Sub on GitHub.