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.
This Interactive Publishing Add-on allows you to build interactive publisher applications as detailed below.
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
Configuring the add-on
The Interactive Publishing Add-on is configurable using the following parameter:
Extension.InteractivePublishing.Token
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 subjects that start with the following subject prefix /__migratorydata__/ipub/
, called meta-subjects.
Therefore, configure the Extension.InteractivePublishing.Token
parameter according to the authorization
method of your MigratoryData server as follows:
- If the parameter Entitlement of your MigratoryData server is set on
Basic
orNone
, then configure this parameter with the value of the parameter EntitlementAllowToken - If the parameter Entitlement
is set on
JWT
, then configure this parameter with a JWT token that includes in the listall
under its sectionpermissions
, the following wildcard subject/__migratorydata__/ipub/*
. - If the parameter Entitlement
is set on
Custom
, then configure this parameter with any entitlement token, provided that your authorization rules authorize it to subscribe and publish on any meta-subject, i.e. subject starting with/__migratorydata__/ipub/
Building interactive publishers
Currently, you can build interactive publishers with MigratoryData Client API for Java.
Advertise interactive subjects
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.
/stocks/*
is supported. However, the following wildcard subject /quotes/nyse/*
is not
currently supported as it has three segments. You need to use the broader wildcard subject /quotes/*
to
advertise the interactive subjects matching /quotes/nyse/*
.
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/
Therefore, configure the parameter of the API method setEntitlementToken()
of your interactive publisher application as follows:
- If the parameter Entitlement of the
MigratoryData server is set on
Basic
orNone
, then configure this API method parameter with the value of the parameter EntitlementAllowToken - If the parameter Entitlement
is set on
JWT
, then configure this API method parameter with a JWT token that includes in the listall
under its sectionpermissions
, the following wildcard subject/__migratorydata__/ipub/*
. - If the parameter Entitlement
is set on
Custom
, then configure this API method parameter with any entitlement token, provided that your authorization rules authorize it to subscribe and publish on any meta-subject, i.e. subjects starting with/__migratorydata__/ipub/
Example of interactive publisher
We provide an example of interactive publisher application on here.