com.r3corda.node.services.api / AbstractNodeService / addMessageHandler

addMessageHandler

protected inline fun <reified Q : ServiceRequestMessage, reified R : Any> addMessageHandler(topic: String, crossinline handler: (Q) -> R, crossinline exceptionConsumer: (Message, Exception) -> Unit): Unit

Register a handler for a message topic. In comparison to using net.addMessageHandler() this manages a lot of common boilerplate code. Exceptions are caught and passed to the provided consumer. If you just want a simple acknowledgement response with no content, use com.r3corda.core.messaging.Ack

Parameters

topic - the topic, without the default session ID postfix (".0)

handler - a function to handle the deserialised request and return an optional response (if return type not Unit)

exceptionConsumer - a function to which any thrown exception is passed.


protected inline fun <reified Q : ServiceRequestMessage, reified R : Any> addMessageHandler(topic: String, crossinline handler: (Q) -> R): Unit

Register a handler for a message topic. In comparison to using net.addMessageHandler() this manages a lot of common boilerplate code. Exceptions are propagated to the messaging layer. If you just want a simple acknowledgement response with no content, use com.r3corda.core.messaging.Ack

Parameters

topic - the topic, without the default session ID postfix (".0)

handler - a function to handle the deserialised request and return an optional response (if return type not Unit)