Developer's Guide and Reference Manual
This guide includes the following sections:
This application programming interface (API) contains all the necessary operations for connecting to a cluster of one or more MigratoryData servers, subscribing to subjects, getting real-time messages for the subscribed subjects, and publishing real-time messages.
A typical API usage is as follows:
For using this API please reference in your web application the file
migratorydata-client.js which is located in the folder
lib of this API package.
If you define two or more MigratoryData servers, then all the MigratoryData servers should provide the same level of data redundancy, by making available for subscription the same set of subjects.
Use the API method MigratoryDataClient.setMessageHandler() to define the message handler, a function defined by your web application that will handle the real-time messages received from a MigratoryData server. The message handler must have the following signature:
function <messageHandlerFunction>(Object messages);
<messageHandlerFunction> can be any function name of your choice. Its
messages argument is an array of messages, where each message in the array is an object having the following properties:
subject- the subject of the message
content- the content of the message
fields- an array of fields where each field is an object with two properties:
name(the name of the field) and
value(the value of the field)
isSnapshot- indicate whether the message is an initial snapshot message or not
Use the API method MigratoryDataClient.setStatusHandler() to define the status handler, a function defined by your web application that will handle the status notifications. The status handler must have the following signature:
function <statusHandlerFunction>(Object status);
<statusHandlerFunction> can be any function name of your choice. Its
status argument is an object having two properties:
type- the type of the status notification
info- the detail information of the status notification
Use the API method MigratoryDataClient.subscribe() to specify interest in receiving real-time messages having as subjects the strings provided in the parameter of this API method. You can call the API method MigratoryDataClient.subscribe() at any time to subscribe to further subjects. To unsubscribe from subscribed subjects, use the API method MigratoryDataClient.unsubscribe().
Use the API method MigratoryDataClient.publish() to publish messages.
Handle the received messages in your message handler defined above, and, optionally, handle the status notifications in your status handler defined above (you may choose to ignore the status notifications by not defining a status handler).
Examples built with this API are available in the folder
examples of this API package; start with the README file which explains how to run them.