The Publish/Subscribe (Pub/Sub) messaging paradigm is used to exchange messages between multiple applications without any knowledge of the sending or receiving applications. The messages are exchanged via an intermediary channel, called a topic. As the name of the model indicates, the applications sending the message are considered publishers, and the recipients of the message are subscribers, as they subscribe to the channel they are interested in.
For example, a set of subscribers can be interested in information about the order shipment details, so that they can process it to track order delivery. Hence, they will subscribe to a topic which relays messages for order details. Once the publisher publishes a message to the topic, the subscribers will be notified and receive the message containing order details to further process it at their end.
Since all Pub/Sub models require a channel for communication, NCache acts as a medium for topics so that the publisher publishes the message to the NCache topic, and subscribers receive the message via the topic after being notified about it. The notification model is Poll based Notification model. Using NCache as medium for topics ensures loose coupling within the model and allows berth to scale with abstraction. This also provides the added benefit of the topics being distributed.
It is recommended to use a separate cache dedicated to Pub/Sub only. This is because of two features of NCache:
Eviction: If the cache is shared for messages and cache items, frequent eviction for cache items may also remove the messages before they are relayed to the subscriber.
State Transfer: State transfer adds a cost over each cache item operation. Since messages are frequently being published, relayed and expired, this recurrent activity can prove costly because it triggers state transfer.
The components in the figure are briefly described below:
A channel through which the publisher and subscriber communicate with each other via messages. A topic maintains the list of subscribers registered to it and the relays the published messages to the subscribers.
The object in interest of the subscribers. Publishers will publish serializable messages irrespective of any subscriber’s knowledge.
Publishes the message to the topic and can optionally receive message delivery failure notification.
Registers itself against the desired topic so that it receives messages related to the topic.
In This Section
Explains in depth the concept and code samples for topics in Pub/Sub model in NCache.
Explains in depth the concept of messages in Pub/Sub model of NCache and provides samples to create messages.
Explain Pub/Sub events to notify the publisher and subscriber about various events happening across the cache and applications.
Publish Messages to Topic
Provides sample code which creates a topic and publishes messages to it.
Subscribe for Topic Messages
Provides sample code to subscribe against a topic and receive messages of interest.
Monitoring Pub/Sub Topics
Describes the ways Pub/Sub statistics can be monitored through NCache Monitor, PerfMon and PowerShell cmdlets.