Class CommandConverter
java.lang.Object
io.axoniq.framework.axonserver.connector.command.CommandConverter
Utility class to convert commands during
dispatching and handling of
subscribed command handlers in the
AxonServerCommandBusConnector.
The operations convert
CommandMessages and
convert
CommandResponses are used during dispatching. The operations
convert Commands and
convert result messages are used during handling.
This utility class is marked as Internal as it is specific for the AxonServerCommandBusConnector.
- Since:
- 5.0.0
- Author:
- Mitchell Herrijgers, Steven van Beelen
-
Method Summary
Modifier and TypeMethodDescriptionstatic CommandMessageconvertCommand(io.axoniq.axonserver.grpc.command.Command command, @Nullable Converter converter) static io.axoniq.axonserver.grpc.command.CommandconvertCommandMessage(CommandMessage command, String clientId, String componentName) convertCommandResponse(io.axoniq.axonserver.grpc.command.CommandResponse commandResponse, @Nullable Converter converter, MessageType fallbackResultType) Converts the givencommandResponseto aCommandResultMessage, wrapped in aCompletableFuturefor convenience when dealing withCommandResponsesduringdispatching.static io.axoniq.axonserver.grpc.command.CommandResponseconvertErrorResponse(String clientId, String requestIdentifier, Throwable cause, @Nullable Converter converter) Converts the givencauseinto aCommandResponsecarrying an error, using the givenrequestIdentifierto correlate theCommandthat led to thisCommandResponse.static io.axoniq.axonserver.grpc.command.CommandResponseconvertResultMessage(CommandResultMessage resultMessage, String requestIdentifier) Converts the givenresultMessageinto aCommandResponse, using the givenrequestIdentifierto correlate theCommandthat led to thisCommandResponse.
-
Method Details
-
convertCommandMessage
public static io.axoniq.axonserver.grpc.command.Command convertCommandMessage(CommandMessage command, String clientId, String componentName) Converts the givencommandinto aCommandfordispatching.Will set the
routing keyandprioritywhen present on the givencommand.- Parameters:
command- the command message to convert to aCommandclientId- the identifier of this application, as specific in theAxonServerConfigurationcomponentName- the name of this application, as specific in theAxonServerConfiguration- Returns:
- the given
commandconverted to aCommand
-
convertCommandResponse
public static CompletableFuture<CommandResultMessage> convertCommandResponse(io.axoniq.axonserver.grpc.command.CommandResponse commandResponse, @Nullable Converter converter, MessageType fallbackResultType) Converts the givencommandResponseto aCommandResultMessage, wrapped in aCompletableFuturefor convenience when dealing withCommandResponsesduringdispatching.- Parameters:
commandResponse- the command response to convert to aCommandResultMessageconverter- the converter to use for payload conversion in the resultingCommandResultMessagefallbackResultType- theMessageTypeto use for the resultingCommandResultMessagewhen the response carries no payload; typically the dispatchedCommandMessage's owntype, as there is no result-specific type to derive one from- Returns:
- the
commandResponseconverted to aCommandResultMessage, wrapped in aCompletableFuturefor convenience. The resultingCommandResultMessagecarries anullpayload when the response carries no result, which is the case when the response's payload has no type, or is typed asVoidwithout data; the future completes exceptionally when the response holds an error
-
convertCommand
public static CommandMessage convertCommand(io.axoniq.axonserver.grpc.command.Command command, @Nullable Converter converter) - Parameters:
command- the command to convert to aCommandMessageconverter- the converter to use for payload conversion in the resultingCommandMessage- Returns:
- the given
commandconverted into aCommandMessage
-
convertResultMessage
public static io.axoniq.axonserver.grpc.command.CommandResponse convertResultMessage(CommandResultMessage resultMessage, String requestIdentifier) Converts the givenresultMessageinto aCommandResponse, using the givenrequestIdentifierto correlate theCommandthat led to thisCommandResponse.When the
resultMessagecarries anullpayload, as is the case for command handlers that do not return a result, theCommandResponsecarries a payload of theresultMessage's type without data. For a handler that returns nothing, that type isVoid, which dispatchers recognize as an empty result.- Parameters:
resultMessage- the result message to convert to aCommandResponserequestIdentifier- the identifier correlating theCommandResponseto theCommandthat led to the response- Returns:
- a
CommandResponsebased on the givenresultMessageandrequestIdentifier
-
convertErrorResponse
public static io.axoniq.axonserver.grpc.command.CommandResponse convertErrorResponse(String clientId, String requestIdentifier, Throwable cause, @Nullable Converter converter) Converts the givencauseinto aCommandResponsecarrying an error, using the givenrequestIdentifierto correlate theCommandthat led to thisCommandResponse.Used when a
subscribedcommand handler completes a command exceptionally.- Parameters:
clientId- the identifier of this application, as specified in theAxonServerConfiguration, used as the location reported in the resulting error messagerequestIdentifier- the identifier correlating theCommandResponseto theCommandthat led to the responsecause- the exception to convert into the error carried by theCommandResponseconverter- the converter to use for serializing application-specific exception details onto the resultingCommandResponse, ornullif no such conversion is available- Returns:
- a
CommandResponsecarrying the error derived from the givencause
-