Class GenericPayload<T>

java.lang.Object
io.smallrye.reactive.messaging.GenericPayload<T>
Type Parameters:
T - the type of the payload

public class GenericPayload<T> extends Object
A generic payload that can be used to wrap a payload with metadata. Allows associating a payload with metadata to be sent as a message, without using signatures supporting Message<T>.
  • Constructor Details

    • GenericPayload

      public GenericPayload(T payload, Metadata metadata)
  • Method Details

    • of

      public static <T> GenericPayload<T> of(T payload)
      Creates a new payload with the given payload and empty metadata.
      Type Parameters:
      T - the type of the payload
      Parameters:
      payload - the payload
      Returns:
      the payload
    • of

      public static <T> GenericPayload<T> of(T payload, Metadata metadata)
      Creates a new payload with the given payload and metadata.
      Type Parameters:
      T - the type of the payload
      Parameters:
      payload - the payload
      metadata - the metadata
      Returns:
      the payload
    • from

      public static <T> GenericPayload<T> from(Message<T> message)
      Creates a new payload from the given message.
      Type Parameters:
      T - the type of the payload
      Parameters:
      message - the message
      Returns:
      the payload
    • getPayload

      public T getPayload()
      Gets the payload associated with this payload.
      Returns:
      the payload
    • getMetadata

      public Metadata getMetadata()
      Gets the metadata associated with this payload.
      Returns:
      the metadata
    • withMetadata

      public GenericPayload<T> withMetadata(Metadata metadata)
      Adds metadata to this payload.
      Parameters:
      metadata - the metadata to add
      Returns:
      a new payload with the added metadata
    • withPayload

      public <R> GenericPayload<R> withPayload(R payload)
      Adds metadata to this payload.
      Parameters:
      payload - the payload to add
      Returns:
      a new payload with the added metadata
    • toMessage

      public Message<T> toMessage()
      Converts this payload to a message.
      Returns:
      the message with the payload and metadata
    • toMessage

      public Message<T> toMessage(Message<?> message)
      Converts this payload to a message, merging the metadata with the given message.
      Parameters:
      message - the message to merge the metadata with
      Returns:
      the message with the payload and merged metadata