Package org.axonframework.messaging.core
Class GenericResultMessage
java.lang.Object
org.axonframework.messaging.core.MessageDecorator
org.axonframework.messaging.core.GenericResultMessage
- All Implemented Interfaces:
Message,ResultMessage
- Direct Known Subclasses:
GenericCommandResultMessage,GenericQueryResponseMessage,GenericSubscriptionQueryUpdateMessage
Generic implementation of
ResultMessage interface.- Since:
- 4.0.0
- Author:
- Milan Savic, Steven van Beelen
-
Field Summary
Fields inherited from interface org.axonframework.messaging.core.Message
RESOURCE_KEY -
Constructor Summary
ConstructorsConstructorDescriptionGenericResultMessage(Message delegate) Constructs aGenericResultMessagefor the givendelegate, intended to reconstruct anotherResultMessage.GenericResultMessage(MessageType type, Object result) GenericResultMessage(MessageType type, Object result, Map<String, String> metadata) Constructs aGenericResultMessagefor the giventype,result, andmetadata. -
Method Summary
Modifier and TypeMethodDescriptionandMetadata(Map<String, String> metadata) static ResultMessageasResultMessage(Object result) Deprecated.protected StringDescribe the type of message, used inMessageDecorator.toString().withConvertedPayload(Type type, Converter converter) Returns a newMessageimplementation with itsMessage.payload()converted to the giventypeby the givenconverter.withMetadata(Map<String, String> metadata) Returns a copy of thisMessage(implementation) with the givenmetadata.Methods inherited from class org.axonframework.messaging.core.MessageDecorator
delegate, describeTo, identifier, metadata, payload, payloadAs, payloadType, toString, typeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.axonframework.messaging.core.Message
identifier, metadata, payload, payloadAs, payloadAs, payloadAs, payloadAs, payloadAs, payloadType, typeMethods inherited from interface org.axonframework.messaging.core.ResultMessage
withConvertedPayload, withConvertedPayload
-
Constructor Details
-
GenericResultMessage
Constructs aGenericResultMessagefor the giventypeandresult.Uses the correlation data of the current Unit of Work, if present.
- Parameters:
type- Thetypefor thisResultMessage.result- The result for thisResultMessage.
-
GenericResultMessage
public GenericResultMessage(@Nonnull MessageType type, @Nullable Object result, @Nonnull Map<String, String> metadata) Constructs aGenericResultMessagefor the giventype,result, andmetadata.- Parameters:
type- Thetypefor thisResultMessage.result- The result for thisResultMessage.metadata- The metadata for thisResultMessage.
-
GenericResultMessage
Constructs aGenericResultMessagefor the givendelegate, intended to reconstruct anotherResultMessage.Unlike the other constructors, this constructor will not attempt to retrieve any correlation data from the Unit of Work.
- Parameters:
delegate- TheMessagecontainingpayload,type,identifierandmetadatafor theQueryResponseMessageto reconstruct.
-
-
Method Details
-
asResultMessage
Deprecated.In favor of using the constructor, as we intend to enforce thinking about thetype.Returns the givenresultas aResultMessageinstance. Ifresultalready implementsResultMessage, it is returned as-is. IfresultimplementsMessage, payload and meta data will be used to construct newGenericResultMessage. Otherwise, the givenresultis wrapped into aGenericResultMessageas its payload.- Parameters:
result- the command result to be wrapped asResultMessage- Returns:
- a Message containing given
resultas payload, orresultif already implementsResultMessage
-
withMetadata
Description copied from interface:MessageReturns a copy of thisMessage(implementation) with the givenmetadata.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 ofMessageto prevent errors further downstream.- Specified by:
withMetadatain interfaceMessage- Specified by:
withMetadatain interfaceResultMessage- Parameters:
metadata- The new metadata for theMessage.- Returns:
- A copy of
this Message (implementation)with the givenmetadata.
-
andMetadata
Description copied from interface:MessageReturns a copy of thisMessage(implementation) with itsmetadatamerged with the givenmetadata.All other fields, like for example the
Message.payload(), remain unchanged.- Specified by:
andMetadatain interfaceMessage- Specified by:
andMetadatain interfaceResultMessage- Parameters:
metadata- The metadata to merge with.- Returns:
- A copy of
this Message (implementation)with the givenmetadata.
-
withConvertedPayload
@Nonnull public ResultMessage withConvertedPayload(@Nonnull Type type, @Nonnull Converter converter) 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.- Specified by:
withConvertedPayloadin interfaceMessage- Specified by:
withConvertedPayloadin interfaceResultMessage- Overrides:
withConvertedPayloadin classMessageDecorator- 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.
-
describeType
Description copied from class:MessageDecoratorDescribe the type of message, used inMessageDecorator.toString().Defaults to the simple class name of the actual instance.
- Overrides:
describeTypein classMessageDecorator- Returns:
- The type of the message.
-
type.