fun addMessageHandler(topic: String, sessionID: Long, executor: Executor?, callback: (Message, MessageHandlerRegistration) -> Unit): MessageHandlerRegistration
The provided function will be invoked for each received message whose topic matches the given string, on the given executor.
If no executor is received then the callback will run on threads provided by the messaging service, and the callback is expected to be thread safe as a result.
The returned object is an opaque handle that may be used to un-register handlers later with removeMessageHandler. The handle is passed to the callback as well, to avoid race conditions whereby the callback wants to unregister itself and yet addMessageHandler hasnt returned the handle yet.
topic
- identifier for the general subject of the message, for example "platform.network_map.fetch".
The topic can be the empty string to match all messages (session ID must be DEFAULT_SESSION_ID).sessionID
- identifier for the session the message is part of. For services listening before
a session is established, use DEFAULT_SESSION_ID.fun addMessageHandler(topicSession: TopicSession, executor: Executor?, callback: (Message, MessageHandlerRegistration) -> Unit): MessageHandlerRegistration
The provided function will be invoked for each received message whose topic and session matches, on the given executor.
If no executor is received then the callback will run on threads provided by the messaging service, and the callback is expected to be thread safe as a result.
The returned object is an opaque handle that may be used to un-register handlers later with removeMessageHandler. The handle is passed to the callback as well, to avoid race conditions whereby the callback wants to unregister itself and yet addMessageHandler hasnt returned the handle yet.
topicSession
- identifier for the topic and session to listen for messages arriving on.