• Webinars
  • Docs
  • Download
  • Blogs
  • Contact Us
Try Free
Show / Hide Table of Contents

Pub/Sub Messages Behaviour and Properties

A message contains the actual data object which is sent by the publisher and delivered to the subscribers via the topic. For example, some subscribers are interested in the order details of a company. A topic is created for the publisher to publish messages related to the orders of a company to it, and all interested subscribers will subscribe to this topic.

Once the publisher publishes the message to the topic, the registered subscribers are notified that a message pertaining to their interest has been published. In case of multiple messages, they are stored in a sequence inside the queue of a particular topic.

Note

The same message can be assigned to multiple topics. This is uniquely identified through an auto generated ID.

Message Properties

You can specify the message delivery options through a DeliveryOption enum on how a message can be delivered. Following are the two delivery options provided by NCache:

  • All: Messages are delivered to all registered subscribers.

  • Any: Messages are delivered to any single registered subscriber. If an acknowledgment is not received, the messages are reassigned to the next subscriber. If an acknowledgment is received, the messages are removed.

Message Behavior

Note

This feature is only available for Enterprise Edition.

Messages are invalidated in case the following criteria is met:

  • Eviction: If eviction is enabled on cache, messages will also be evicted from topics using LRU(Least Recently Used),LFU(Least Frequently Used), or priority based policy.

    • If the cache being used for Pub/Sub transactions is the same as the one being used for normal caching, the first priority of eviction will always be cache data.

    • If cache data is not available for eviction, then messages will be evicted. This will ensure that messages will only be evicted in extreme cases or when cache is dedicated for Pub/Sub only.

  • Expiration: Expiration can be enabled on messages as with cache items. The messages will be expired from the cache as soon as the expiration interval has passed and uses the same cleaning interval mechanism.

  • Clear Cache: Messages are removed along with cache items once the cache is cleared.

  • Cache Restart: Similar to clear cache, cache contents are cleared when the cache is restarted. This also includes all topics and the messages contained within them.

Storage and Distribution

  • Messages are distributed among nodes based upon topologies.

    • For Partition of Replica and Partitioned topologies, hash-based distribution is used.

    • For Replicated topology, messages are replicated to all nodes of the clustered cache. However, the coordinator node is responsible for message manipulation.

    • For Mirror topology, messages are published to the active node and then replicated to the passive node accordingly.

  • If message store is near eviction, an event is logged which indicates that the store is full and eviction has started.

  • Messages have an overhead on cache memory. Hence, message size is considered while calculating the cache size.

Encryption and Compression

Note

This feature is only available for Enterprise Edition.

Encryption and compression that is configured at cache level also applies to topic message payload.

State Transfer

In case of state transfer, when messages move to another node in the cluster, the node where the message is finally stored is responsible for delivery.

Note

There is a chance of subscribers receiving duplicate messages during state transfer.

Ordered Messages

Note

This feature is only available in NCache 5.2 and onward.

NCache now supports ordered messages where the sequence of the messages is maintained on the client-side. A user can specify a sequence name for a chunk of messages, and the ordered messages are delivered to the subscribers in the exact same order they are published in. The sequence string should be the same for a chain of ordered messages. Using the sequence string, all the messages reside on the same node using the Location Affinity mechanism.

Following are the important characteristics of ordered messages:

  • Messages from a publisher with the same sequence reside on a single cache node.

  • If the DeliveryOption is set to Any, all the ordered messages of the same sequence are delivered to the same subscriber. In case the specific subscriber loses connection or becomes unavailable, a new subscriber is reassigned for this purpose. However, if the DeliveryOption is set to All, then all ordered messages of the same sequence are delivered to all the subscribers.

  • In case of state transfer, the ordered messages might lose their sequence and get published without keeping the order.

  • Ordered messages can only be published using the Sync mode in the Publish API. Bulk and Async API calls are not supported.

Additional Resources

NCache provides a 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

Back to top Copyright © 2017 Alachisoft