We have just released official support for interactive publishing to MigratoryData as an off-the-shelf add-on to the MigratoryData server. It allows you to build interactive publisher applications. To this end, we have enhanced the client API to be able to advertise interactive subjects to the MigratoryData cluster for getting subscription events. Hence, an interactive publisher application will get the following subscription events for an interactive subject it advertises: when a first client subscribes to it,  across the MigratoryData cluster, and when a last client unsubscribes from it, across the MigratoryData cluster. The interactive publisher application could use these subscription events to start publishing messages when an interactive subject has a first subscriber and stop publishing messages when the last subscriber unsubscribes from an interactive subject.

Overview

MigratoryData is a decoupled pub/sub messaging server where publishers and subscribers do not need to know each other. The client that publishes a message on a subject does not know if there is a client subscribed to that subject or not. This decoupling way of removing any dependencies between publishers and subscribers makes our pub/sub server scalable and appropriate for WebSocket messaging environments that are asynchronous by nature.

In general, publishing a message on a subject with no subscribers is reasonable because the MigratoryServer server can handle millions of concurrent subjects. MigratoryData can be also configured to retain in memory the most recent messages of a subject. Therefore, when a first subscriber connects, it will get immediately the most recent messages for the subscribed subject.

That being said, there are situations when a publisher should produce messages for a large number of subjects, while clients subscribe and unsubscribe frequently to small subsets of those subjects. Updating all subjects and keeping their most recent messages in memory would be a resource waste both in term of network and memory utilization. In this situation, but also in other use cases, it could be more efficient or practical for the publisher to know when a client subscribes for the first time to a subject, across the entire MigratoryData cluster, to start publishing messages for that subject. Also, if the publisher would know when the last client unsubscribes from a subject, across the entire MigratoryData cluster, it could stop publishing messages on that subject. Publishing in this way would be therefore interactive.

Enabling the add-on

The Interactive Publishing Add-on is preinstalled in the MigratoryData server 6.x, but it is disabled by default. To enable it, configure the parameter Extension.InteractivePublishing as follows:

Extension.InteractivePublishing = true

In a MigratoryData cluster, the Interactive Publishing add-on of a node communicates with the Interactive Publishing add-ons of the other cluster nodes, as well as with the interactive publishers of the MigratoryData cluster, using a number of meta-subjects, i.e. subjects that start with the following subject prefix /__migratorydata__/ipub/.

Publishing and subscribing on these meta-subjects to the MigratoryData cluster, the Interactive Publishing add-on should be configured with an entitlement token authorized by the entitlement method used by the MigratoryData cluster to subscribe and publish on these meta-subjects. The entitlement token of the Interactive Publishing add-on should be provided using the following parameter:

Extension.InteractivePublishing.Token

See in the documentation of the Interactive Publishing Add-on how to configure this parameter according to the entitlement method used by your MigratoryData cluster.

Building interactive publishers

Currently, you can build interactive publishers with MigratoryData Client API for Java.

An interactive subject is a subject for which the API triggers subscription events, i.e. when a first client subscribes to it and a last client unsubscribes from it, across the MigratoryData cluster.

The following API method should be used to advertise the interactive subjects to the MigratoryData cluster:

public void advertiseInteractiveSubjects(List<String> wildcardSubjects)

A wildcard subject is a MigratoryData subject where the last segment is *. For example, by using the wildcard subject /stocks/ibm/* in the argument of this API method, it will advertise the interactive subjects that start with /stocks/ibm/, e.g. /stocks/ibm/bid, /stocks/ibm/level2/price etc.

Implement interactive listener

In the case of usual, non-interactive publisher applications, you normally implement the interface MigratoryDataListener and register it using the following API method to get status notifications and data messages in real-time:

public void setListener(MigratoryDataListener listener)

In the case of interactive publisher applications, you should implement the following interface MigratoryDataInteractiveListener, which extends MigratoryDataListener, and register it using the same API method above setListener() to get status notifications and data messages, as well as subscription events for the interactive subjects:

public interface MigratoryDataInteractiveListener extends MigratoryDataListener {
	/**
	 * Indicates that a first client has subscribed to the subject in 
     * the argument, across the entire MigratoryData cluster.
	 *
	 * @param subject Subject subscribed by its first subscriber.
	 */
	public void onSubscribe(String subject);
	
	/**
	 * Indicates that the last client subscribed to the subject in 
     * the argument, across the entire MigratoryData cluster, has 
     * unsubscribed.
	 *
	 * @param subject Subject unsubscribed by its last subscriber.
	 */
	public void onUnsubscribe(String subject);
}

Authorize meta-subjects

The entitlement token that your publisher application defines with the API method setEntitlementToken() must be authorized by the MigratoryData server to publish/subscribe on the subjects handled by your application as usual.

In addition, the MigratoryData server should authorize publications and subscriptions for the entitlement token of your interactive publisher application for the meta-subjects, i.e. the subjects that start with the following prefix /__migratorydata__/ipub/.

See in the documentation of the Interactive Publishing Add-on how to define an entitlement token for the API method setEntitlementToken() of your interactive publisher application according to the entitlement method used by your MigratoryData cluster.

Getting started with Interactive Publishing to MigratoryData

To get started please read the Interactive Publishing Add-on documentation.