Interface MessageListener<T extends ChannelPayload>

Type Parameters:
T - the type of payload this listener handles; must extend ChannelPayload
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface MessageListener<T extends ChannelPayload>
Callback for handling messages received on a typed MessageChannel.

This is a @FunctionalInterface and may be used as a lambda expression. Register an instance via MessageChannel.listen(MessageListener), which returns a Subscription that can be used to cancel the listener.

The listener receives the message metadata and the deserialized payload:


 (ctx, payload) -> {
     String from = ctx.from().id();
     long sentAt = ctx.timestamp();
 }
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept(MessageContext<T> ctx, T payload)
    Invoked when a message matching this listener's payload type is received.
  • Method Details

    • accept

      void accept(MessageContext<T> ctx, T payload)
      Invoked when a message matching this listener's payload type is received.
      Parameters:
      ctx - the metadata for the received message, including the sending server's identity (MessageContext.from()) and the send timestamp (MessageContext.timestamp())
      payload - the deserialized message payload