A Sticky Subscription is defined as a subscription (trading or market data) that remains active until the Customer Application explicitly unsubscribes. This means that if the connection to the exchange goes down, the subscription is NOT cancelled. The Whisperer application will automatically re-subscribe to the Trading Venue.
As before, the Customer Application will be notified that a Trading Venue is down with a SubscriptionEventMessage message where the status field is set to ERROR. However, with Sticky Subscriptions set to true, the Customer Application does not need to re-subscribe. Once the Trading Venue is back online, the Customer Application will be notified with a SubscriptionEventMessage message where the status field set to ENABLED.
To enable sticky subscriptions, call setStickySubscriptions(true). This forces all future subscriptions to be set to sticky.
Note
It is important to note that subscriptions initiated before the setStickySubscriptions(true) is explicitly made remain non-sticky (re-subscriptions are necessary.)
There is an optional second argument to setStickySubscriptions(): clearSubscriptionsOnStop. This defaults to true in the description above, meaning that if the client disconnects from Whisperer with the onDisconnected() or onStop() callbacks, all sticky subscriptions will be cleared.
The customer must resubscribe after these callbacks to continue receiving data. When passed false for this argument, sticky will be preserved on disconnect and the customer must only subscribe once within the MFClient lifetime. Note that sticky subscriptions, and state in general, only apply to single instances of MFClient, which is to say that no state is shared between MFClient instances.
The following is an example of the sequence of messages where the sticky subscription is set and the market data subscription becomes temporarily disabled.
It is important to note that following the SubscriptionEventMessage message with status set
to ERROR, the Whisperer will automatically resubscribe and will only send the SubscriptionEventMessage
message with the status field set to ENABLED message once it is able to successfully subscribe.
Even if the Trading Venue is down at the time of the initial subscription request and a SubscriptionEventMessage message with status set to ERROR, is initially received, the Whisperer will continue to re-try and will notify the Customer Application when the subscription is finally enabled due to a successful connection.
Figure 8.10. – Sticky Subscription Example. When onSubscriptionEvent() is invoked, the reason field is set to something like "reason="Connection to ECN is down""
The MFClient object keeps track of all sticky subscriptions and it will automatically resubscribe once it reconnects to the Whisperer server. A sticky subscription persists over client disconnections from the server as well (either requested by the client through .stop() or unexpected). This means that if the connection to Whisperer goes down, the subscription is NOT considered cancelled.