Make Data Persist in Liberator
When a StreamLink application publishes data to Liberator, the data does not normally persist within Liberator if the connection to the Liberator is lost. You can use the persistent
configuration attribute to ensure that the data does persist across reconnections. When persistent
is set to true, if the application reconnects to the Liberator (or to a different Liberator, depending on the failover configuration), StreamLink automatically resends the data. Let’s look at an example of this in action:
1. Change end-user mode
Let’s say that the Liberator has an object /MyMode
representing a mode that the end-user is in, and the default mode of this object is "A". When StreamLink logs an end-user in to Liberator, the mode starts off as "A". To change the end-user to mode "B", send the following publish command:
myCommandListener = new MyCommandListener(); fields = {"mode": "B"}; streamLink.publishToSubject("/MyMode", fields, myCommandListener);
2. Specify persistent configuration
If the end-user is disconnected from the Liberator, the user session is lost. With the coding in the previous step, when StreamLink reconnects, the end-user’s mode will have defaulted back to mode "A". If you want the mode to be automatically set to "B" again when StreamLink reconnects, specify the persistent configuration attribute as true:
myCommandListener = new MyCommandListener(); fields = {"mode": "B"}; myCommandParameters = {"persistent": true} streamLink.publishToSubject("/MyMode", fields, myCommandListener, myCommandParameters);
This code ensures that the object /MyMode
with field "mode=B" is reliably sent to the Liberator whenever a reconnect occurs.
3. Remove persistent configuration
Let’s say that you subsequently no longer want the /MyMode
state to persist in mode "B", simply remove the persistence, as follows:
myCommandListener = new MyCommandListener(); fields = {"mode": "B"}; myCommandParameters = {"persistent": true} myCommandSubscription = streamLink.publishToSubject("/MyMode", fields, myCommandListener, myCommandParameters); ... /* Some time later, myMode no longer needs to be persisted...*/ myCommandSubscription.unPersist();
Note that after the call to unPersist()
, /MyMode
remains in mode "B" until such time as StreamLink reconnects to the Liberator.