Class GenericResultMessage

java.lang.Object
org.axonframework.messaging.core.MessageDecorator
org.axonframework.messaging.core.GenericResultMessage
All Implemented Interfaces:
Message, ResultMessage
Direct Known Subclasses:
GenericCommandResultMessage, GenericQueryResponseMessage, GenericSubscriptionQueryUpdateMessage

public class GenericResultMessage extends MessageDecorator implements ResultMessage
Generic implementation of ResultMessage interface.
Since:
4.0.0
Author:
Milan Savic, Steven van Beelen
  • Constructor Details

    • GenericResultMessage

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

      Uses the correlation data of the current Unit of Work, if present.

      Parameters:
      type - The type for this ResultMessage.
      result - The result for this ResultMessage.
    • GenericResultMessage

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

      public GenericResultMessage(@Nonnull Message delegate)
      Constructs a GenericResultMessage for the given delegate, intended to reconstruct another ResultMessage.

      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, type, identifier and metadata for the QueryResponseMessage to reconstruct.
  • Method Details

    • asResultMessage

      @Deprecated public static ResultMessage asResultMessage(Object result)
      Deprecated.
      In favor of using the constructor, as we intend to enforce thinking about the type.
      Returns the given result as a ResultMessage instance. If result already implements ResultMessage, it is returned as-is. If result implements Message, payload and meta data will be used to construct new GenericResultMessage. Otherwise, the given result is wrapped into a GenericResultMessage as its payload.
      Parameters:
      result - the command result to be wrapped as ResultMessage
      Returns:
      a Message containing given result as payload, or result if already implements ResultMessage
    • withMetadata

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

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

      @Nonnull public ResultMessage 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
      Specified by:
      withConvertedPayload in interface ResultMessage
      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.
    • 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.