Package org.axonframework.messaging
Interface ResultMessage<R>
- Type Parameters:
R- The type of payload contained in this Message
- All Superinterfaces:
Message<R>,Serializable
- All Known Subinterfaces:
CommandResultMessage<R>,QueryResponseMessage<T>,SubscriptionQueryUpdateMessage<U>
- All Known Implementing Classes:
ConvertingResponseMessage,GenericCommandResultMessage,GenericQueryResponseMessage,GenericResultMessage,GenericSubscriptionQueryUpdateMessage,GrpcBackedResponseMessage
Message that represents a result of handling some form of request message.
- Since:
- 4.0
- Author:
- Milan Savic
-
Method Summary
Modifier and TypeMethodDescriptionandMetaData(Map<String, ?> metaData) Returns a copy of this Message with it MetaData merged with the givenmetaData.default <D> Optional<D> If the this message contains an exception result, returns the details provided in the exception, if available.default ThrowableReturns the exception result.booleanIndicates whether the ResultMessage represents unsuccessful execution.Returns the Exception in case of exceptional result message or an emptyOptionalin case of successful execution.default <T> SerializedObject<T> serializeExceptionResult(Serializer serializer, Class<T> expectedRepresentation) Serializes the exception result.default <S> SerializedObject<S> serializePayload(Serializer serializer, Class<S> expectedRepresentation) Serialize the payload of this message to theexpectedRepresentationusing givenserializer.withMetaData(Map<String, ?> metaData) Returns a copy of this Message with the givenmetaData.Methods inherited from interface org.axonframework.messaging.Message
getIdentifier, getMetaData, getPayload, getPayloadType, serializeMetaData
-
Method Details
-
isExceptional
boolean isExceptional()Indicates whether the ResultMessage represents unsuccessful execution.- Returns:
trueif execution was unsuccessful,falseotherwise
-
optionalExceptionResult
Returns the Exception in case of exceptional result message or an emptyOptionalin case of successful execution.- Returns:
- an
Optionalcontaining exception result or an empty Optional in case of a successful execution
-
exceptionResult
Returns the exception result. This method is to be called ifisExceptional()returnstrue.- Returns:
- a
Throwabledefining the exception result - Throws:
IllegalStateException- if this ResultMessage is not exceptional
-
exceptionDetails
If the this message contains an exception result, returns the details provided in the exception, if available. If this message does not carry an exception result, or the exception result doesn't provide any application-specific details, an empty optional is returned.- Type Parameters:
D- The type of application-specific details expected- Returns:
- an optional containing application-specific error details, if present
-
serializePayload
default <S> SerializedObject<S> serializePayload(Serializer serializer, Class<S> 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.- Specified by:
serializePayloadin interfaceMessage<R>- Type Parameters:
S- 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
-
serializeExceptionResult
default <T> SerializedObject<T> serializeExceptionResult(Serializer serializer, Class<T> expectedRepresentation) Serializes the exception result. Will create aRemoteExceptionDescriptionfrom theOptionalexception in this ResultMessage instead of serializing the original exception.- Type Parameters:
T- the generic type representing the expected format- Parameters:
serializer- theSerializerused to serialize the exceptionexpectedRepresentation- aClassrepresenting the expected format- Returns:
- the serialized exception as a
SerializedObject
-
withMetaData
Description copied from interface:MessageReturns 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.- Specified by:
withMetaDatain interfaceMessage<R>- Parameters:
metaData- The new MetaData for the Message- Returns:
- a copy of this message with the given MetaData
-
andMetaData
Description copied from interface:MessageReturns a copy of this Message with it MetaData merged with the givenmetaData. The payload remains unchanged.- Specified by:
andMetaDatain interfaceMessage<R>- Parameters:
metaData- The MetaData to merge with- Returns:
- a copy of this message with the given MetaData
-