Package org.axonframework.messaging
Interface Message<T>
- Type Parameters:
T- the type of payload contained in this Message
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
CommandMessage<T>,CommandResultMessage<R>,DeadlineMessage<T>,DomainEventMessage<T>,EventMessage<T>,QueryMessage<T,,R> QueryResponseMessage<T>,ResetContext<T>,ResultMessage<R>,StreamingQueryMessage<Q,,R> SubscriptionQueryMessage<Q,,I, U> SubscriptionQueryUpdateMessage<U>,TrackedEventMessage<T>
- All Known Implementing Classes:
AbstractMessage,ConvertingResponseMessage,GenericCommandMessage,GenericCommandResultMessage,GenericDeadlineMessage,GenericDomainEventMessage,GenericEventMessage,GenericMessage,GenericQueryMessage,GenericQueryResponseMessage,GenericResetContext,GenericResultMessage,GenericStreamingQueryMessage,GenericSubscriptionQueryMessage,GenericSubscriptionQueryUpdateMessage,GenericTrackedDomainEventMessage,GenericTrackedEventMessage,GrpcBackedCommandMessage,GrpcBackedQueryMessage,GrpcBackedResponseMessage,GrpcBackedSubscriptionQueryMessage,MessageDecorator,SerializedMessage
Representation of a Message, containing a Payload and MetaData. Typical examples of Messages are Commands, Events and
Queries.
Instead of implementing
Message directly, consider implementing CommandMessage, EventMessage or QueryMessage instead.- Since:
- 2.0
- Author:
- Allard Buijze
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionandMetaData(Map<String, ?> metaData) Returns a copy of this Message with it MetaData merged with the givenmetaData.Returns the identifier of this message.Returns the meta data for this message.Returns the payload of this message.Returns the type of the payload.default <R> SerializedObject<R> serializeMetaData(Serializer serializer, Class<R> expectedRepresentation) Serialize the meta data of this message to theexpectedRepresentationusing givenserializer.default <R> SerializedObject<R> serializePayload(Serializer serializer, Class<R> expectedRepresentation) Serialize the payload of this message to theexpectedRepresentationusing givenserializer.withMetaData(Map<String, ?> metaData) Returns a copy of this Message with the givenmetaData.
-
Method Details
-
getIdentifier
String getIdentifier()Returns the identifier of this message. Two messages with the same identifiers should be interpreted as different representations of the same conceptual message. In such case, the meta-data may be different for both representations. The payload may be identical.- Returns:
- the unique identifier of this message
-
getMetaData
MetaData getMetaData()Returns the meta data for this message. This meta data is a collection of key-value pairs, where the key is a String, and the value is a serializable object.- Returns:
- the meta data for this message
-
getPayload
T getPayload()Returns the payload of this message. The payload is the application-specific information.- Returns:
- the payload of this message
-
getPayloadType
Returns the type of the payload. Is semantically equal togetPayload().getClass(), but allows implementations to optimize by using lazy loading or deserialization.- Returns:
- the type of payload.
-
withMetaData
Returns a copy of this Message with the givenmetaData. The payload remains unchanged. While the implementation returned may be different than the implementation ofthis, implementations must take special care in returning the same type of Message (e.g. EventMessage, DomainEventMessage) to prevent errors further downstream.- Parameters:
metaData- The new MetaData for the Message- Returns:
- a copy of this message with the given MetaData
-
andMetaData
Returns a copy of this Message with it MetaData merged with the givenmetaData. The payload remains unchanged.- Parameters:
metaData- The MetaData to merge with- Returns:
- a copy of this message with the given MetaData
-
serializePayload
default <R> SerializedObject<R> serializePayload(Serializer serializer, Class<R> expectedRepresentation) Serialize the payload of this message to theexpectedRepresentationusing givenserializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.- Type Parameters:
R- The type of the serialized data- Parameters:
serializer- The serializer to serialize payload withexpectedRepresentation- The type of data to serialize to- Returns:
- a SerializedObject containing the serialized representation of the message's payload
-
serializeMetaData
default <R> SerializedObject<R> serializeMetaData(Serializer serializer, Class<R> expectedRepresentation) Serialize the meta data of this message to theexpectedRepresentationusing givenserializer. This method should return the same SerializedObject instance when invoked multiple times using the same serializer.- Type Parameters:
R- The type of the serialized data- Parameters:
serializer- The serializer to serialize meta data withexpectedRepresentation- The type of data to serialize to- Returns:
- a SerializedObject containing the serialized representation of the message's meta data
-