Class GenericDomainEventMessage<T>

Type Parameters:
T - The type of payload contained in this Message
All Implemented Interfaces:
Serializable, DomainEventMessage<T>, EventMessage<T>, Message<T>
Direct Known Subclasses:
GenericTrackedDomainEventMessage

public class GenericDomainEventMessage<T> extends GenericEventMessage<T> implements DomainEventMessage<T>
Generic implementation of a DomainEventMessage.
See Also:
  • Constructor Details

    • GenericDomainEventMessage

      public GenericDomainEventMessage(String type, String aggregateIdentifier, long sequenceNumber, T payload)
      Initialize a DomainEventMessage originating from an Aggregate with the given aggregateIdentifier, with given sequenceNumber and payload. The MetaData of the message is empty.
      Parameters:
      type - The domain type
      aggregateIdentifier - The identifier of the aggregate generating this message
      sequenceNumber - The message's sequence number
      payload - The application-specific payload of the message
    • GenericDomainEventMessage

      public GenericDomainEventMessage(String type, String aggregateIdentifier, long sequenceNumber, T payload, Map<String,?> metaData)
      Initialize a DomainEventMessage originating from an Aggregate with the given aggregateIdentifier, with given sequenceNumber and payload and metaData.
      Parameters:
      type - The domain type
      aggregateIdentifier - The identifier of the aggregate generating this message
      sequenceNumber - The message's sequence number
      payload - The application-specific payload of the message
      metaData - The MetaData to attach to the message
    • GenericDomainEventMessage

      public GenericDomainEventMessage(String type, String aggregateIdentifier, long sequenceNumber, T payload, Map<String,?> metaData, String messageIdentifier, Instant timestamp)
      Initialize a DomainEventMessage originating from an Aggregate using existing data.
      Parameters:
      type - The domain type
      aggregateIdentifier - The identifier of the aggregate generating this message
      sequenceNumber - The message's sequence number
      payload - The application-specific payload of the message
      metaData - The MetaData to attach to the message
      messageIdentifier - The message identifier
      timestamp - The event's timestamp
    • GenericDomainEventMessage

      public GenericDomainEventMessage(String type, String aggregateIdentifier, long sequenceNumber, Message<T> delegate, Supplier<Instant> timestamp)
      Initialize a DomainEventMessage originating from an Aggregate using existing data. The timestamp of the event is supplied lazily to prevent unnecessary deserialization of the timestamp.
      Parameters:
      type - The domain type
      aggregateIdentifier - The identifier of the aggregate generating this message
      sequenceNumber - The message's sequence number
      delegate - The delegate message providing the payload, metadata and identifier of the event
      timestamp - The event's timestamp supplier
    • GenericDomainEventMessage

      public GenericDomainEventMessage(String type, String aggregateIdentifier, long sequenceNumber, Message<T> delegate, Instant timestamp)
      Initialize a DomainEventMessage originating from an Aggregate with the given aggregateIdentifier, with given sequenceNumber and payload, metaData and timestamp.
      Parameters:
      type - the aggregate type
      aggregateIdentifier - the aggregate identifier
      sequenceNumber - the sequence number of the event
      delegate - The delegate message providing the payload, metadata and identifier of the event
      timestamp - the timestamp of the event
  • Method Details

    • getType

      public String getType()
      Description copied from interface: DomainEventMessage
      Returns the type of the Aggregate that generated this DomainEvent. By default this is equal to the simple class name of the aggregate root.
      Specified by:
      getType in interface DomainEventMessage<T>
      Returns:
      the type of the Aggregate that generated this DomainEvent
    • getAggregateIdentifier

      public String getAggregateIdentifier()
      Description copied from interface: DomainEventMessage
      Returns the identifier of the Aggregate that generated this DomainEvent. Note that the value returned does not necessarily have to be the same instance that was provided at creation time. It is possible that (due to serialization, for example) the value returned here has a different structure.
      Specified by:
      getAggregateIdentifier in interface DomainEventMessage<T>
      Returns:
      the identifier of the Aggregate that generated this DomainEvent
    • getSequenceNumber

      public long getSequenceNumber()
      Description copied from interface: DomainEventMessage
      Returns the sequence number that allows DomainEvents originating from the same Aggregate to be placed in the order of generation.
      Specified by:
      getSequenceNumber in interface DomainEventMessage<T>
      Returns:
      the sequence number of this Event
    • withMetaData

      public GenericDomainEventMessage<T> withMetaData(@Nonnull Map<String,?> metaData)
      Description copied from interface: EventMessage
      Returns a copy of this EventMessage with the given metaData. The payload, Timestamp and Identifier remain unchanged.
      Specified by:
      withMetaData in interface DomainEventMessage<T>
      Specified by:
      withMetaData in interface EventMessage<T>
      Specified by:
      withMetaData in interface Message<T>
      Overrides:
      withMetaData in class GenericEventMessage<T>
      Parameters:
      metaData - The new MetaData for the Message
      Returns:
      a copy of this message with the given MetaData
    • andMetaData

      public GenericDomainEventMessage<T> andMetaData(@Nonnull Map<String,?> metaData)
      Description copied from interface: EventMessage
      Returns a copy of this EventMessage with it MetaData merged with the given metaData. The payload, Timestamp and Identifier remain unchanged.
      Specified by:
      andMetaData in interface DomainEventMessage<T>
      Specified by:
      andMetaData in interface EventMessage<T>
      Specified by:
      andMetaData in interface Message<T>
      Overrides:
      andMetaData in class GenericEventMessage<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 GenericEventMessage<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 GenericEventMessage<T>
      Returns:
      the type of message