Class GenericMessage
- All Implemented Interfaces:
Message
Message interface containing the payload and
metadata in deserialized form.
This Message implementation is "conversion aware," as it maintains any conversion results from
payloadAs(Type, Converter) and withConvertedPayload(Type, Converter) (either invoked with a
Class, TypeReference, or Type), together with the hash of the given Converter. In
doing so, this Message optimizes subsequent payloadAs/withConvertedPayload invocations for the same
type-and-converter combination. If this optimization should be disabled, the "AXON_CONVERSION_CACHE_ENABLED"
system property can be set to false.
- Since:
- 2.0.0
- Author:
- Allard Buijze, Steven van Beelen
-
Field Summary
Fields inherited from interface org.axonframework.messaging.core.Message
RESOURCE_KEY -
Constructor Summary
ConstructorsConstructorDescriptionGenericMessage(String identifier, MessageType type, Object payload, Map<String, String> metadata) Constructs aGenericMessagefor the givenidentifier,type,payload, andmetadata, intended to reconstruct anotherMessage.GenericMessage(String identifier, MessageType type, P payload, Class<P> declaredPayloadType, Map<String, String> metadata) Constructs aGenericMessagefor the givenidentifier,type,payload, andmetadata, intended to reconstruct anotherMessage.GenericMessage(MessageType type, Object payload) Constructs aGenericMessagefor the giventypeandpayload.GenericMessage(MessageType type, Object payload, Map<String, String> metadata) Constructs aGenericMessagefor the giventype,payload, andmetadata.GenericMessage(MessageType type, P payload, Class<P> declaredPayloadType, Map<String, String> metadata) Constructs aGenericMessagefor the giventype,payload,declaredPayloadType, andmetadata. -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageConstruct an empty message.metadata()Returns theMetadatafor thisMessage.payload()Returns the payload of thisMessage.<T> TReturns the payload of thisMessage, converted to the giventypeby the givenconverter.Class<?> Returns the type of the payload.withConvertedPayload(Type type, Converter converter) Returns a newMessageimplementation with itsMessage.payload()converted to the giventypeby the givenconverter.protected MessagewithMetadata(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.core.AbstractMessage
andMetadata, identifier, type, withMetadataMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.axonframework.messaging.core.Message
payloadAs, payloadAs, payloadAs, payloadAs, withConvertedPayload, withConvertedPayload
-
Constructor Details
-
GenericMessage
Constructs aGenericMessagefor the giventypeandpayload.Uses the correlation data of the current Unit of Work, if present.
-
GenericMessage
public GenericMessage(@Nonnull MessageType type, @Nullable Object payload, @Nonnull Map<String, String> metadata) -
GenericMessage
public GenericMessage(@Nonnull MessageType type, @Nullable P payload, @Nonnull Class<P> declaredPayloadType, @Nonnull Map<String, String> metadata) Constructs aGenericMessagefor the giventype,payload,declaredPayloadType, andmetadata.The given
metadatais merged with the Metadata from the correlation data of the current Unit of Work, if present. -
GenericMessage
public GenericMessage(@Nonnull String identifier, @Nonnull MessageType type, @Nullable Object payload, @Nonnull Map<String, String> metadata) Constructs aGenericMessagefor the givenidentifier,type,payload, andmetadata, intended to reconstruct anotherMessage.Unlike the other constructors, this constructor will not attempt to retrieve any correlation data from the Unit of Work. If you in tend to construct a new
GenericMessage, please useGenericMessage(MessageType, Object)instead. -
GenericMessage
public GenericMessage(@Nonnull String identifier, @Nonnull MessageType type, @Nullable P payload, @Nonnull Class<P> declaredPayloadType, @Nonnull Map<String, String> metadata) Constructs aGenericMessagefor the givenidentifier,type,payload, andmetadata, intended to reconstruct anotherMessage.Unlike the other constructors, this constructor will not attempt to retrieve any correlation data from the Unit of Work. If you in tend to construct a new
GenericMessage, please useGenericMessage(MessageType, Object)instead.- Type Parameters:
P- The generic type of the expected payload of the resulting object.- Parameters:
identifier- The identifier of thisMessage.type- Thetypefor thisMessage.payload- The payload of typePfor thisMessage.declaredPayloadType- The declared type of thepayloadof thisMessage.metadata- The metadata for thisMessage.
-
-
Method Details
-
emptyMessage
Construct an empty message.- Returns:
- A message with
nullMessage.payload(), noMetadata, and aMessage.type()of"empty".
-
payload
Description copied from interface:MessageReturns the payload of thisMessage.The payload is the application-specific information.
- Returns:
- The payload of this
Message.
-
payloadAs
Description copied from interface:MessageReturns the payload of thisMessage, converted to the giventypeby the givenconverter.If the given
typeis an instance ofClassandMessage.payloadType()isassignable fromthatClass,Message.payload()may be invoked instead of using the givenconverter.Implementers of this operation may optimize by storing the converted payloads, thus saving a
Converter.convert(Object, Class)invocation in the process. Only when this optimization is in place will anull converterresult in a successful invocation of this method.- Type Parameters:
T- The generic type to convert thisMessage'spayload to.- Parameters:
type- The type to convert thisMessage'spayload to.converter- The converter to convert thisMessage'spayload with.- Returns:
- The payload of this
Message, converted to the giventype.
-
payloadType
Description copied from interface:MessageReturns the type of the payload.Is semantically equal to
getPayload().getClass(), but allows implementations to optimize by using lazy loading or deserialization.- Returns:
- The type of payload.
-
metadata
Description copied from interface:MessageReturns theMetadatafor thisMessage.The
Metadatais a collection of key-value pairs, where both the key and values areStrings.- Returns:
- The
Metadatafor thisMessage.
-
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- Parameters:
metadata- The metadata in the new message- Returns:
- a copy of this instance with given metadata
-
withConvertedPayload
Description copied from interface:MessageReturns a newMessageimplementation with itsMessage.payload()converted to the giventypeby the givenconverter. This newMessageis effectively a copy ofthis Messagewith a renewed payload andMessage.payloadType().Will return the
thisinstance if thepayload typeisassignable fromthe converted result.- Parameters:
type- The type to convert theMessage.payload()to.converter- The converter to convert theMessage.payload()with.- Returns:
- A new
Messageimplementation with itsMessage.payload()converted to the giventypeby the givenconverter.
-