Package org.axonframework.messaging
Class GenericMessage<T>
java.lang.Object
org.axonframework.messaging.AbstractMessage<T>
org.axonframework.messaging.GenericMessage<T>
- All Implemented Interfaces:
Serializable,Message<T>
Generic implementation of a
Message that contains the payload and metadata as unserialized values.
If a GenericMessage is created while a UnitOfWork is active it copies
over the correlation data of the UnitOfWork to the created message.
- Since:
- 2.0
- Author:
- Allard Buijze
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a Message for the givenpayloadandmeta data.Constructor to reconstruct a Message using existing data.GenericMessage(String identifier, T payload, Map<String, ?> metaData) Constructor to reconstruct a Message using existing data.GenericMessage(T payload) Constructs a Message for the givenpayloadusing the correlation data of the current Unit of Work, if present.GenericMessage(T payload, Map<String, ?> metaData) Constructs a Message for the givenpayloadandmeta data. -
Method Summary
Modifier and TypeMethodDescriptionstatic Message<?> Returns a Message representing the givenpayloadOrMessage, either by wrapping it or by returning it as-is.Returns the meta data for this message.Returns the payload of this message.Returns the type of the payload.<R> SerializedObject<R> serializeMetaData(Serializer serializer, Class<R> expectedRepresentation) Serialize the meta data of this message to theexpectedRepresentationusing givenserializer.<R> SerializedObject<R> serializePayload(Serializer serializer, Class<R> expectedRepresentation) Serialize the payload of this message to theexpectedRepresentationusing givenserializer.withMetaData(MetaData metaData) Returns a new message instance with the same payload and properties as this message but givenmetaData.Methods inherited from class org.axonframework.messaging.AbstractMessage
andMetaData, getIdentifier, withMetaData
-
Constructor Details
-
GenericMessage
Constructs a Message for the givenpayloadusing the correlation data of the current Unit of Work, if present.- Parameters:
payload- The payload for the message
-
GenericMessage
Constructs a Message for the givenpayloadandmeta data. The givenmetaDatais merged with the MetaData from the correlation data of the current unit of work, if present. In case thepayload == null,Voidwill be used as thepayloadType.- Parameters:
payload- The payload for the message as a genericTmetaData- The meta dataMapfor the message
-
GenericMessage
Constructs a Message for the givenpayloadandmeta data. The givenmetaDatais merged with the MetaData from the correlation data of the current unit of work, if present.- Parameters:
declaredPayloadType- The declared type of message payloadpayload- The payload for the messagemetaData- The meta data for the message
-
GenericMessage
Constructor to reconstruct a Message using existing data. Note that no correlation data from a UnitOfWork is attached when using this constructor. If you're constructing a new Message, useGenericMessage(Object, Map)instead.- Parameters:
identifier- The identifier of the Messagepayload- The payload of the messagemetaData- The meta data of the message- Throws:
NullPointerException- when the givenpayloadisnull.
-
GenericMessage
public GenericMessage(String identifier, Class<T> declaredPayloadType, T payload, Map<String, ?> metaData) Constructor to reconstruct a Message using existing data. Note that no correlation data from a UnitOfWork is attached when using this constructor. If you're constructing a new Message, useGenericMessage(Object, Map)instead- Parameters:
identifier- The identifier of the MessagedeclaredPayloadType- The declared type of message payloadpayload- The payload for the messagemetaData- The meta data for the message
-
-
Method Details
-
asMessage
Returns a Message representing the givenpayloadOrMessage, either by wrapping it or by returning it as-is. If the givenpayloadOrMessagealready implementsMessage, it is returned as-is, otherwise aMessageis returned with the parameter as its payload.- Parameters:
payloadOrMessage- The payload to wrap or message to return- Returns:
- a Message with the given payload or the message
-
getMetaData
Description copied from interface:MessageReturns 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
Description copied from interface:MessageReturns the payload of this message. The payload is the application-specific information.- Returns:
- the payload of this message
-
getPayloadType
Description copied from interface:MessageReturns 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
Description copied from class:AbstractMessageReturns a new message instance with the same payload and properties as this message but givenmetaData.- Specified by:
withMetaDatain classAbstractMessage<T>- Parameters:
metaData- The metadata in the new message- Returns:
- a copy of this instance with given metadata
-
serializePayload
public <R> SerializedObject<R> serializePayload(Serializer serializer, Class<R> expectedRepresentation) Description copied from interface:MessageSerialize 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
public <R> SerializedObject<R> serializeMetaData(Serializer serializer, Class<R> expectedRepresentation) Description copied from interface:MessageSerialize 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
-