Class GenericCommandMessage

java.lang.Object
org.axonframework.messaging.core.MessageDecorator
org.axonframework.messaging.commandhandling.GenericCommandMessage
All Implemented Interfaces:
CommandMessage, Message

public class GenericCommandMessage extends MessageDecorator implements CommandMessage
Generic implementation of the CommandMessage interface.
Since:
2.0.0
Author:
Allard Buijze, Steven van Beelen
  • Constructor Details

    • GenericCommandMessage

      public GenericCommandMessage(@Nonnull MessageType type, @Nullable Object payload)
      Constructs a GenericCommandMessage for the given type and payload.

      The Metadata defaults to an empty instance.

      Parameters:
      type - The type for this CommandMessage.
      payload - The payload for this CommandMessage.
    • GenericCommandMessage

      public GenericCommandMessage(@Nonnull MessageType type, @Nullable Object payload, @Nonnull Map<String,String> metadata)
      Constructs a GenericCommandMessage for the given type, payload, and metadata.
      Parameters:
      type - The type for this CommandMessage.
      payload - The payload for this CommandMessage.
      metadata - The metadata for this CommandMessage.
    • GenericCommandMessage

      public GenericCommandMessage(@Nonnull MessageType type, @Nonnull Object payload, @Nonnull Map<String,String> metadata, @Nullable String routingKey, @Nullable Integer priority)
      Constructs a GenericCommandMessage for the given type, payload, and metadata.

      Optionally, a routingKey and/or a priority may be passed.

      Parameters:
      type - The type for this CommandMessage.
      payload - The payload for this CommandMessage.
      metadata - The metadata for this CommandMessage.
      routingKey - The routing key for this CommandMessage, if any.
      priority - The priority for this CommandMessage, if any.
    • GenericCommandMessage

      public GenericCommandMessage(@Nonnull Message delegate)
      Constructs a GenericCommandMessage with given delegate.

      The delegate will be used supply the payload, type, metadata and identifier of the resulting GenericCommandMessage.

      Unlike the other constructors, this constructor will not attempt to retrieve any correlation data from the Unit of Work.

      Parameters:
      delegate - The Message containing payload, qualifiedName, identifier and metadata for the CommandMessage to reconstruct.
    • GenericCommandMessage

      public GenericCommandMessage(@Nonnull Message delegate, @Nullable String routingKey, @Nullable Integer priority)
      Constructs a GenericCommandMessage with given delegate, routingKey, and priority.

      The delegate will be used supply the payload, type, metadata and identifier of the resulting GenericCommandMessage.
      Optionally, a routingKey and/or a priority may be passed.

      Unlike the other constructors, this constructor will not attempt to retrieve any correlation data from the Unit of Work.

      Parameters:
      delegate - The Message containing payload, qualifiedName, identifier and metadata for the CommandMessage to reconstruct.
      routingKey - The routing key for this CommandMessage, if any.
      priority - The priority for this CommandMessage, if any.
  • Method Details

    • routingKey

      public Optional<String> routingKey()
      Description copied from interface: CommandMessage
      Returns the routing key for this command message, if any is applicable.

      Commands with the same routing key should be routed to the same handler if possible, as they are likely related and might have to be executed in a specific order.

      Specified by:
      routingKey in interface CommandMessage
      Returns:
      The routing key for this command message, or an empty Optional if no routing key is set.
    • priority

      public OptionalInt priority()
      Description copied from interface: CommandMessage
      Returns the priority of this CommandMessage, if any is applicable.

      Commands with a higher priority should be handled before commands with a lower priority. Commands without a priority are considered to have the lowest priority.

      Specified by:
      priority in interface CommandMessage
      Returns:
      The priority of this command message, or an empty OptionalInt if no priority is set.
    • withMetadata

      @Nonnull public CommandMessage 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 CommandMessage
      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 CommandMessage 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 CommandMessage
      Specified by:
      andMetadata in interface Message
      Parameters:
      metadata - The metadata to merge with.
      Returns:
      A copy of this Message (implementation) with the given metadata.
    • withConvertedPayload

      @Nonnull public CommandMessage withConvertedPayload(@Nonnull Type type, @Nonnull Converter converter)
      Description copied from interface: Message
      Returns a new Message implementation with its Message.payload() converted to the given type by the given converter. This new Message is effectively a copy of this Message with a renewed payload and Message.payloadType().

      Will return the this instance if the payload type is assignable from the converted result.

      Specified by:
      withConvertedPayload in interface CommandMessage
      Specified by:
      withConvertedPayload in interface Message
      Overrides:
      withConvertedPayload in class MessageDecorator
      Parameters:
      type - The type to convert the Message.payload() to.
      converter - The converter to convert the Message.payload() with.
      Returns:
      A new Message implementation with its Message.payload() converted to the given type by the given converter.
    • describeTo

      protected void describeTo(StringBuilder stringBuilder)
      Description copied from class: MessageDecorator
      Describe the message specific properties to the given stringBuilder. Subclasses should override this method, calling the super method and appending their own properties to the end (or beginning).

      As convention, String values should be enclosed in single quotes, Objects in curly brackets and numeric values may be appended without enclosing. All properties should be preceded by a comma when appending, or finish with a comma when prefixing values.

      Overrides:
      describeTo in class MessageDecorator
      Parameters:
      stringBuilder - The builder to append data to.
    • describeType

      protected String describeType()
      Description copied from class: MessageDecorator
      Describe the type of message, used in MessageDecorator.toString().

      Defaults to the simple class name of the actual instance.

      Overrides:
      describeType in class MessageDecorator
      Returns:
      The type of the message.