Service topic data in JavaScript Classic API
The JavaScript® API provides a basic interface for using service topics.
The API consists of a service topic handler to process responses and using the generic DiffusionClient.command(...) method to send service requests.
- Add a topic listener, to capture the service topic load message
- Subscribe to the service topic
- With the initial topic load (ITL) from the service topic create a service topic handler
- Remove the topic listener
- Send command messages to the service
- Process any response in the function passed to the handler
To create a handler using the DiffusionClient.createServiceTopicHandler(TopicMessage, function) you must pass in the ITL of the service topic and the function that is called when a service response is received. This function will be called with a CommandMessage as an argument.
To make service requests you must use the DiffusionClient.command(string,string,TopicMessage) method to send command messages. The first string is the command to send. The second string is a correlation ID for the response. The TopicMessage is the message sent to the client with the correct topic and any additional headers or payload you want to send in the request.
Use an ordinary topic listener to get the ITL to create the service topic handler. This listener is not required for any subsequent message processing and you are encouraged to remove it after you have the ITL.
You must generate a unique value for the correlation ID.