Interface CommandMessage

All Superinterfaces:
Message
All Known Implementing Classes:
GenericCommandMessage

public interface CommandMessage extends Message
A Message carrying a command as its payload.

These messages carry an intention to change application state.

Since:
2.0.0
Author:
Allard Buijze
  • Method Details

    • routingKey

      Optional<String> routingKey()
      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.

      Returns:
      The routing key for this command message, or an empty Optional if no routing key is set.
    • priority

      OptionalInt priority()
      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.

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

      @Nonnull 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 Message
      Parameters:
      metadata - The new metadata for the Message.
      Returns:
      A copy of this Message (implementation) with the given metadata.
    • andMetadata

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

      @Nonnull default CommandMessage withConvertedPayload(@Nonnull Class<?> 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 Message
      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.
    • withConvertedPayload

      @Nonnull default CommandMessage withConvertedPayload(@Nonnull TypeReference<?> 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 Message
      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.
    • withConvertedPayload

      @Nonnull 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 Message
      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.