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

Pub/Sub Subscription Types, Policies, and Methods

NCache provides multiple types of Pub/Sub subscriptions. In Pub/Sub, a subscription represents an interest of a subscriber(s) shown in a particular topic. This subscriber is considered to be the client application that registers itself to a topic of interest through a subscription. In the sections below, we discuss the types, policies, and the methods of subscriptions supported by NCache.

Note

In case a new node is added to the cache cluster and state transfer is triggered, all subscriptions along with the messages and cache data are replicated to the new node.

Durable and NonDurable Subscriptions in NCache

Types of Subscriptions

NCache provides support for the following types of subscriptions:

Non-Durable Subscription

In a non-durable subscription, the messages intended for the subscriber are conveyed only until the subscriber remains connected. If the subscriber leaves the network, it will not be able to receive the messages that were published during its disconnection period.

Also, non-durable subscriptions are automatically deleted when the subscriber leaves the network. This means that if that subscriber rejoins or establishes the connection again, it will be considered as a new subscription. By default, all subscriptions created on a topic are non-durable subscriptions.

Durable Subscription

In a durable subscription, it is ensured that the subscriber does not miss out on any message and, upon rejoining in case of disconnection, the subscriber will receive all corresponding messages. Meaning, durable subscriptions are not impacted due to subscriber disconnection and re-connection.

If a subscriber is disconnected, the messages intended for this subscriber are stored on a server until the subscriber rejoins or the messages are expired. Durable subscriptions are not deleted automatically on subscriber disconnection unless the subscriber has properly unsubscribed.

Subscription Policies

NCaches provides support for the following policies for subscriptions:

Shared

Important

This policy is only supported by Durable Subscription

In this policy, a subscription can have more than one active subscriber registered at a time. The basic purpose is load sharing. For sending messages to multiple subscribers using a shared subscription, the Round Robin method is adopted. Even if any subscriber leaves the network, the messages will continue to be distributed between active subscribers.

In a shared subscription, the subscription will remain on the topic and cannot be unsubscribed until all subscribers have unsubscribed. This means as long as there is even a single active subscriber, the subscription will stay active.

Exclusive

In this policy, one subscription can only have one active subscriber registered at a time. Until the connection is active, no new subscriber request on the same subscription is accepted. Both types of subscriptions (non-durable and durable) support this subscription policy.

Methods of Subscription

NCache provides support for the following methods of subscription:

Normal

This is the normal method of subscription where the subscriber has to provide the name of the topic it wishes to register a subscription against. If the subscriber wishes to register a subscription against multiple topics, it will have to make multiple calls. For details, refer to Subscribe for Topic Messages.

Pattern-Based

Note

This feature is only available for NCache Enterprise edition.

Using this method of subscription, subscribers can provide patterns to subscribe to multiple topics with a single call. For this, it is important that the topics matching the pattern already exist on the server. Once the subscription(s) is successfully created on the pattern-based topic, the subscribers receive messages published on topics that match the pattern. Also, if a topic is created after the pattern-based-subscription has been registered against the pattern provided by subscriber, it will register that subscriber against that topic.

Similarly, regarding un-registering from a topic, this method unsubscribes the subscriber against all the matching topics with provided pattern without affecting any other subscription using this call.

Note
  • A subscriber can only get pattern-based topic. However, a subscriber is not allowed to create it.
  • A pattern can be used by the publisher only to receive failure notifications.

Supported Wildcards

Pattern-based method of subscription supports the following three wildcards:

  1. * : zero or many characters. For example, bl* subscribes to black, blue, and blur etc.
  2. ? : any one character. For example, h?t subscribes to hit, hot and hat etc.
  3. [] : range of characters. For example, b[ae]t subscribes to bet and bat, but not bit.

Expiration of Subscriptions

You can give expiration as a parameter for subscriptions. However, it is optional. If any subscription is created with expiration time defined, as long as it has active subscribers, each time the subscriber polls or performs any other activity, the expiration time is reset.

The expiration time starts at the instance of subscriber inactivity. If the subscriber remains inactive for the entire expiration time period defined, the subscription will be expired. Once the subscription expires, it will be removed from all cache nodes.

Additional Resources

NCache provides a sample application for Pub/Sub on GitHub.

See Also

Pub/Sub Messaging
Pub/Sub Topics
Pub/Sub Messages
Pub/Sub Events

Back to top Copyright © 2017 Alachisoft