com.r3corda.node.services.messaging / ArtemisMessagingService / addMessageHandler

# addMessageHandler

`fun addMessageHandler(topic: String, executor: Executor?, callback: (Message, MessageHandlerRegistration) -> Unit): MessageHandlerRegistration`
Overrides MessagingService.addMessageHandler

The provided function will be invoked for each received message whose topic matches the given string, on the given executor. The topic can be the empty string to match all messages.

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.