Class CommandConverter

java.lang.Object
io.axoniq.framework.axonserver.connector.command.CommandConverter

@Internal public final class CommandConverter extends Object
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 Details

    • convertCommandMessage

      public static io.axoniq.axonserver.grpc.command.Command convertCommandMessage(CommandMessage command, String clientId, String componentName)
      Converts the given command into a Command for dispatching.

      Will set the routing key and priority when present on the given command.

      Parameters:
      command - the command message to convert to a Command
      clientId - the identifier of this application, as specific in the AxonServerConfiguration
      componentName - the name of this application, as specific in the AxonServerConfiguration
      Returns:
      the given command converted to a Command
    • convertCommandResponse

      public static CompletableFuture<CommandResultMessage> convertCommandResponse(io.axoniq.axonserver.grpc.command.CommandResponse commandResponse, @Nullable Converter converter, MessageType fallbackResultType)
      Converts the given commandResponse to a CommandResultMessage, wrapped in a CompletableFuture for convenience when dealing with CommandResponses during dispatching.
      Parameters:
      commandResponse - the command response to convert to a CommandResultMessage
      converter - the converter to use for payload conversion in the resulting CommandResultMessage
      fallbackResultType - the MessageType to use for the resulting CommandResultMessage when the response carries no payload; typically the dispatched CommandMessage's own type, as there is no result-specific type to derive one from
      Returns:
      the commandResponse converted to a CommandResultMessage, wrapped in a CompletableFuture for convenience. The resulting CommandResultMessage carries a null payload when the response carries no result, which is the case when the response's payload has no type, or is typed as Void without 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)
      Converts the given command into a CommandMessage for handling in subscribed command handlers.
      Parameters:
      command - the command to convert to a CommandMessage
      converter - the converter to use for payload conversion in the resulting CommandMessage
      Returns:
      the given command converted into a CommandMessage
    • convertResultMessage

      public static io.axoniq.axonserver.grpc.command.CommandResponse convertResultMessage(CommandResultMessage resultMessage, String requestIdentifier)
      Converts the given resultMessage into a CommandResponse, using the given requestIdentifier to correlate the Command that led to this CommandResponse.

      When the resultMessage carries a null payload, as is the case for command handlers that do not return a result, the CommandResponse carries a payload of the resultMessage's type without data. For a handler that returns nothing, that type is Void, which dispatchers recognize as an empty result.

      Parameters:
      resultMessage - the result message to convert to a CommandResponse
      requestIdentifier - the identifier correlating the CommandResponse to the Command that led to the response
      Returns:
      a CommandResponse based on the given resultMessage and requestIdentifier
    • convertErrorResponse

      public static io.axoniq.axonserver.grpc.command.CommandResponse convertErrorResponse(String clientId, String requestIdentifier, Throwable cause, @Nullable Converter converter)
      Converts the given cause into a CommandResponse carrying an error, using the given requestIdentifier to correlate the Command that led to this CommandResponse.

      Used when a subscribed command handler completes a command exceptionally.

      Parameters:
      clientId - the identifier of this application, as specified in the AxonServerConfiguration, used as the location reported in the resulting error message
      requestIdentifier - the identifier correlating the CommandResponse to the Command that led to the response
      cause - the exception to convert into the error carried by the CommandResponse
      converter - the converter to use for serializing application-specific exception details onto the resulting CommandResponse, or null if no such conversion is available
      Returns:
      a CommandResponse carrying the error derived from the given cause