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.
Note
This feature is also available in NCache Professional.
Message Delivery Failure Notification
In Pub/Sub, the 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.
A 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 becomes full. When the cache becomes full, it will not 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 notification.
Message Received Notification
The 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 for 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 is deleted, the subscribers can then handle their execution accordingly through event notifications and prevent an infinite waiting state.
The publisher can avoid sending messages to a non-existing Topic and handle any pending payloads and future execution accordingly.
Additional Resources
NCache provides a sample application for Pub/Sub on GitHub.
See Also
.NET: Alachisoft.NCache.Runtime.Caching namespace.
Java: com.alachisoft.ncache.runtime.caching namespace.
Python: ncache.client.services class.
Node.js: Topic class.