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) 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(@Nullable CommandResultMessage resultMessage, String requestIdentifier) Converts the givenresultMessage, when present, into 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) 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 resultingCommandResultMessage- Returns:
- the
commandResponseconverted to aCommandResultMessage, wrapped in aCompletableFuturefor convenience
-
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(@Nullable CommandResultMessage resultMessage, String requestIdentifier) Converts the givenresultMessage, when present, into aCommandResponse, using the givenrequestIdentifierto correlate theCommandthat led to thisCommandResponse.Whenever the
resultMessageisnull, an emptyCommandResponseis constructed instead for returning a result from handling of asubscribedcommand handler.- Parameters:
resultMessage- the result message to convert to aCommandResponse, when presentrequestIdentifier- 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
-