Class GenericCommandMessage<T>

java.lang.Object
org.axonframework.messaging.MessageDecorator<T>
org.axonframework.commandhandling.GenericCommandMessage<T>
Type Parameters:
T - The type of payload contained in this Message
All Implemented Interfaces:
Serializable, CommandMessage<T>, Message<T>

public class GenericCommandMessage<T> extends MessageDecorator<T> implements CommandMessage<T>
Implementation of the CommandMessage that takes all properties as constructor parameters.
Since:
2.0
Author:
Allard Buijze
See Also:
  • Constructor Details

    • GenericCommandMessage

      public GenericCommandMessage(@Nonnull T payload)
      Create a CommandMessage with the given command as payload and empty metaData
      Parameters:
      payload - the payload for the Message
    • GenericCommandMessage

      public GenericCommandMessage(@Nonnull T payload, @Nonnull Map<String,?> metaData)
      Create a CommandMessage with the given command as payload.
      Parameters:
      payload - the payload for the Message
      metaData - The meta data for this message
    • GenericCommandMessage

      public GenericCommandMessage(@Nonnull Message<T> delegate, @Nonnull String commandName)
      Create a CommandMessage from the given delegate message containing payload, metadata and message identifier, and the given commandName.
      Parameters:
      delegate - the delegate message
      commandName - The name of the command
  • Method Details

    • asCommandMessage

      public static <C> CommandMessage<C> asCommandMessage(@Nonnull Object command)
      Returns the given command as a CommandMessage. If command already implements CommandMessage, it is returned as-is. When the command is another implementation of Message, the Message.getPayload() and Message.getMetaData() are used as input for a new GenericCommandMessage. Otherwise, the given command is wrapped into a GenericCommandMessage as its payload.
      Parameters:
      command - The command to wrap as CommandMessage.
      Returns:
      A CommandMessage containing given command as payload, a command if it already implements CommandMessage, or a CommandMessage based on the result of Message.getPayload() and Message.getMetaData() for other Message implementations.
    • getCommandName

      public String getCommandName()
      Description copied from interface: CommandMessage
      Returns the name of the command to execute. This is an indication of what should be done, using the payload as parameter.
      Specified by:
      getCommandName in interface CommandMessage<T>
      Returns:
      the name of the command
    • withMetaData

      public GenericCommandMessage<T> withMetaData(@Nonnull Map<String,?> metaData)
      Description copied from interface: CommandMessage
      Returns a copy of this CommandMessage with the given metaData. The payload remains unchanged.

      While the implementation returned may be different than the implementation of this, implementations must take special care in returning the same type of Message (e.g. EventMessage, DomainEventMessage) to prevent errors further downstream.

      Specified by:
      withMetaData in interface CommandMessage<T>
      Specified by:
      withMetaData in interface Message<T>
      Parameters:
      metaData - The new MetaData for the Message
      Returns:
      a copy of this message with the given MetaData
    • andMetaData

      public GenericCommandMessage<T> andMetaData(@Nonnull Map<String,?> metaData)
      Description copied from interface: CommandMessage
      Returns a copy of this CommandMessage with it MetaData merged with the given metaData. The payload remains unchanged.
      Specified by:
      andMetaData in interface CommandMessage<T>
      Specified by:
      andMetaData in interface Message<T>
      Parameters:
      metaData - The MetaData to merge with
      Returns:
      a copy of this message with the given MetaData
    • 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<T>
      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<T>
      Returns:
      the type of message