Interface EventMessage

All Superinterfaces:
Message
All Known Implementing Classes:
GenericEventMessage, TerminalEventMessage

public interface EventMessage extends Message
A Message wrapping an event, which is represented by its payload.

An event is a representation of an occurrence of an event (i.e. anything that happened any might be of importance to any other component) in the application. It contains the data relevant for components that need to act based on that event.

Since:
2.0.0
Author:
Allard Buijze
See Also:
  • invalid reference
    DomainEventMessage
  • Method Details

    • identifier

      String identifier()
      Returns the identifier of this event.

      The identifier is used to define the uniqueness of an event. Two events may contain similar (or equal) payloads and timestamp, if the event identifiers are different, they both represent a different occurrence of an Event.

      If two messages have the same identifier, they both represent the same unique occurrence of an event, even though the resulting view may be different. You may not assume two messages are equal (i.e. interchangeable) if their identifier is equal.

      For example, an AddressChangeEvent may occur twice for the same event, because someone moved back to the previous address. In that case, the event payload is equal for both EventMessage instances, but the event identifier is different for both.

      Specified by:
      identifier in interface Message
      Returns:
      The identifier of this event.
    • timestamp

      Instant timestamp()
      Returns the timestamp of this event.

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

      Returns:
      The timestamp of this event.
    • withMetadata

      EventMessage withMetadata(Map<String,@Nullable 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

      EventMessage andMetadata(Map<String,@Nullable 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

      default EventMessage withConvertedPayload(Class<?> type, 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

      default EventMessage withConvertedPayload(TypeReference<?> type, 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

      EventMessage withConvertedPayload(Type type, 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.