Class AbstractMessage

java.lang.Object
org.axonframework.messaging.core.AbstractMessage
All Implemented Interfaces:
Message
Direct Known Subclasses:
GenericMessage

public abstract class AbstractMessage extends Object implements Message
Abstract base class for Messages.
Since:
3.0.0
Author:
Rene de Waele, Steven van Beelen
  • Constructor Details

    • AbstractMessage

      public AbstractMessage(@Nonnull String identifier, @Nonnull MessageType type)
      Initializes a new Message with given identifier and type.
      Parameters:
      identifier - The identifier of this Message.
      type - The type for this Message.
  • Method Details

    • identifier

      @Nonnull public String identifier()
      Description copied from interface: Message
      Returns the identifier of this Message.

      Two messages with the same identifiers should be interpreted as different representations of the same conceptual message. In such case, the metadata may be different for both representations. The payload may be identical.

      Specified by:
      identifier in interface Message
      Returns:
      The unique identifier of this Message.
    • type

      @Nonnull public MessageType type()
      Description copied from interface: Message
      Returns the message type of this Message.
      Specified by:
      type in interface Message
      Returns:
      The message type of this Message.
    • withMetadata

      @Nonnull public Message withMetadata(@Nonnull Map<String,String> metadata)
      Description copied from interface: Message
      Returns a copy of this Message (implementation) with the given metadata.

      All other fields, like for example the Message.payload(), remain unchanged.

      While the implementation returned may be different from the implementation of this, implementations must take special care in returning the same type of Message to prevent errors further downstream.

      Specified by:
      withMetadata in interface Message
      Parameters:
      metadata - The new metadata for the Message.
      Returns:
      A copy of this Message (implementation) with the given metadata.
    • andMetadata

      @Nonnull public Message andMetadata(@Nonnull Map<String,String> metadata)
      Description copied from interface: Message
      Returns a copy of this Message (implementation) with its metadata merged with the given metadata.

      All other fields, like for example the Message.payload(), remain unchanged.

      Specified by:
      andMetadata in interface Message
      Parameters:
      metadata - The metadata to merge with.
      Returns:
      A copy of this Message (implementation) with the given metadata.
    • withMetadata

      protected abstract Message withMetadata(Metadata metadata)
      Returns a new message instance with the same payload and properties as this message but given metadata.
      Parameters:
      metadata - The metadata in the new message
      Returns:
      a copy of this instance with given metadata