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)
      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
      Returns:
      the commandResponse converted to a CommandResultMessage, wrapped in a CompletableFuture for convenience
    • 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(@Nullable CommandResultMessage resultMessage, String requestIdentifier)
      Converts the given resultMessage, when present, into a CommandResponse, using the given requestIdentifier to correlate the Command that led to this CommandResponse.

      Whenever the resultMessage is null, an empty CommandResponse is constructed instead for returning a result from handling of a subscribed command handler.

      Parameters:
      resultMessage - the result message to convert to a CommandResponse, when present
      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