interface MessagingServiceA MessagingService sits at the boundary between a message routing / networking layer and the core platform code.
A messaging system must provide the ability to send 1:many messages, potentially to an abstract "group", the
membership of which is defined elsewhere. Messages are atomic and the system guarantees that a sent message
Example implementations might be a custom P2P layer, Akka, Apache Kafka, etc. It is assumed that the message layer
is
| myAddress |
abstract val myAddress: SingleMessageRecipientReturns an address that refers to this node. |
| addMessageHandler |
abstract fun addMessageHandler(topic: String = "", sessionID: Long = DEFAULT_SESSION_ID, executor: Executor? = null, callback: (Message, MessageHandlerRegistration) -> Unit): MessageHandlerRegistrationThe provided function will be invoked for each received message whose topic matches the given string, on the given executor. abstract fun addMessageHandler(topicSession: TopicSession, executor: Executor? = null, callback: (Message, MessageHandlerRegistration) -> Unit): MessageHandlerRegistrationThe provided function will be invoked for each received message whose topic and session matches, on the given executor. |
| createMessage |
abstract fun createMessage(topic: String, sessionID: Long = DEFAULT_SESSION_ID, data: ByteArray): Messageabstract fun createMessage(topicSession: TopicSession, data: ByteArray): MessageReturns an initialised Message with the current time, etc, already filled in. |
| removeMessageHandler |
abstract fun removeMessageHandler(registration: MessageHandlerRegistration): UnitRemoves a handler given the object returned from addMessageHandler. The callback will no longer be invoked once this method has returned, although executions that are currently in flight will not be interrupted. |
| send |
abstract fun send(message: Message, target: MessageRecipients): UnitSends a message to the given receiver. The details of how receivers are identified is up to the messaging implementation: the type system provides an opaque high level view, with more fine grained control being available via type casting. Once this function returns the message is queued for delivery but not necessarily delivered: if the recipients are offline then the message could be queued hours or days later. |
| runOnNextMessage |
fun MessagingService.runOnNextMessage(topic: String, sessionID: Long, executor: Executor? = null, callback: (Message) -> Unit): UnitRegisters a handler for the given topic and session ID that runs the given callback with the message and then removes itself. This is useful for one-shot handlers that arent supposed to stick around permanently. Note that this callback doesnt take the registration object, unlike the callback to MessagingService.addMessageHandler, as the handler is automatically deregistered before the callback runs. fun MessagingService.runOnNextMessage(topicSession: TopicSession, executor: Executor? = null, callback: (Message) -> Unit): UnitRegisters a handler for the given topic and session that runs the given callback with the message and then removes itself. This is useful for one-shot handlers that arent supposed to stick around permanently. Note that this callback doesnt take the registration object, unlike the callback to MessagingService.addMessageHandler. |
| send |
fun MessagingService.send(topic: String, sessionID: Long, payload: Any, to: MessageRecipients): Unitfun MessagingService.send(topicSession: TopicSession, payload: Any, to: MessageRecipients): Unit |
| MessagingServiceInternal |
interface MessagingServiceInternal : MessagingService |