Class GenericEventMessage

java.lang.Object
org.axonframework.messaging.core.MessageDecorator
org.axonframework.messaging.eventhandling.GenericEventMessage
All Implemented Interfaces:
Message, EventMessage
Direct Known Subclasses:
TerminalEventMessage

public class GenericEventMessage extends MessageDecorator implements EventMessage
Generic implementation of the EventMessage interface.
Since:
2.0.0
Author:
Allard Buijze, Rene de Waele, Steven van Beelen
  • Field Details

    • clock

      @Internal @Deprecated public static Clock clock
      Deprecated.
      #3083 - Configure application wide Clock
      Clock instance used to set the time on new events. To fix the time while testing set this value to a constant value.
  • Constructor Details

    • GenericEventMessage

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

      The Metadata defaults to an empty instance.

      Parameters:
      type - The type for this EventMessage.
      payload - The payload for this EventMessage.
    • GenericEventMessage

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

      public GenericEventMessage(@Nonnull String identifier, @Nonnull MessageType type, @Nullable Object payload, @Nonnull Map<String,String> metadata, @Nonnull Instant timestamp)
      Constructs a GenericEventMessage for the given identifier, type, payload, metadata, and timestamp.
      Parameters:
      identifier - The identifier of this EventMessage.
      type - The type for this EventMessage.
      payload - The payload for this EventMessage.
      metadata - The metadata for this EventMessage.
      timestamp - The timestamp of this EventMessage's creation.
    • GenericEventMessage

      public GenericEventMessage(@Nonnull Message delegate, @Nonnull Supplier<Instant> timestampSupplier)
      Constructs a GenericEventMessage for the given delegate and timestampSupplier, intended to reconstruct another EventMessage.

      The timestamp of the event is supplied lazily through the given timestampSupplier to prevent unnecessary deserialization of the timestamp.

      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 EventMessage to reconstruct.
      timestampSupplier - Supplier for the timestamp of the EventMessage's creation.
    • GenericEventMessage

      protected GenericEventMessage(@Nonnull Message delegate, @Nonnull Instant timestamp)
      Constructs a GenericEventMessage with given delegate and timestamp.

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

      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 EventMessage to reconstruct.
      timestamp - The timestamp of this GenericEventMessage's creation.
  • Method Details

    • timestamp

      @Nonnull public Instant timestamp()
      Description copied from interface: EventMessage
      Returns the timestamp of this event.

      The timestamp is set to the date and time the event was reported.

      Specified by:
      timestamp in interface EventMessage
      Returns:
      The timestamp of this event.
    • withMetadata

      @Nonnull public EventMessage 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 EventMessage
      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 EventMessage 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 EventMessage
      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 EventMessage 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 EventMessage
      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.