Class QueryConverter

java.lang.Object
org.axonframework.axonserver.connector.query.QueryConverter

@Internal public final class QueryConverter extends Object
Utility class to convert queries during dispatching and handling of subscribed query handlers in the AxonServerQueryBusConnector.

This utility class is marked as Internal as it is specific for the AxonServerQueryBusConnector.

Since:
5.0.0
Author:
Steven van Beelen
  • Method Details

    • convertQueryRequest

      @Nonnull public static QueryMessage convertQueryRequest(@Nonnull io.axoniq.axonserver.grpc.query.QueryRequest queryRequest)
      Converts a QueryRequest into a QueryMessage.

      This method processes the given QueryRequest by extracting its payload, metadata, and other relevant fields to construct a QueryMessage that represents the request for querying information.

      Parameters:
      queryRequest - The QueryRequest to be converted into a QueryMessage. Must not be null.
      Returns:
      A QueryMessage representation of the provided QueryRequest. The returned object contains the extracted payload, metadata, and expected response type.
      Throws:
      NullPointerException - if the provided QueryRequest is null.
    • convertQueryMessage

      public static io.axoniq.axonserver.grpc.query.QueryRequest convertQueryMessage(@Nonnull QueryMessage query, @Nonnull String clientId, @Nonnull String componentName)
      Converts a QueryMessage into a QueryRequest.

      This method processes the provided QueryMessage and constructs a corresponding QueryRequest with all necessary details, such as metadata, payload, and other processing instructions.

      Parameters:
      query - The QueryMessage to be converted. Must not be null. The payload must be of type byte[], otherwise an IllegalArgumentException is thrown.
      clientId - The identifier of the client making the query. Must not be null.
      componentName - The name of the component handling the query. Must not be null.
      Returns:
      a QueryRequest That represents the provided QueryMessage. Contains the extracted metadata, payload, and other specific configurations from the original message.
      Throws:
      IllegalArgumentException - if the payload of the QueryMessage is not of type byte[].
    • convertQueryResponse

      public static QueryResponseMessage convertQueryResponse(@Nonnull io.axoniq.axonserver.grpc.query.QueryResponse queryResponse)
      Converts a QueryResponse into a QueryResponseMessage.

      This method processes the given QueryResponse, extracts its payload, metadata, and other necessary components to construct a corresponding QueryResponseMessage. If the QueryResponse contains an error, an appropriate exception is included in the resulting QueryResponseMessage.

      Parameters:
      queryResponse - The QueryResponse to be converted. Must not be null. The QueryResponse should contain valid payload and metadata details necessary to construct the resulting QueryResponseMessage.
      Returns:
      A QueryResponseMessage representation of the provided QueryResponse. The returned message includes the processed payload, metadata, and any error information, if applicable.
      Throws:
      IllegalArgumentException - if the provided QueryResponse contains an error, in which case we use ExceptionConverter.convertToAxonException(String, ErrorMessage, SerializedObject).
    • convertQueryResponseMessage

      public static io.axoniq.axonserver.grpc.query.QueryResponse convertQueryResponseMessage(@Nonnull String requestId, @Nonnull QueryResponseMessage queryResponseMessage)
      Converts a QueryResponseMessage into a QueryResponse.

      This method processes the provided QueryResponseMessage to construct a corresponding QueryResponse. The resulting QueryResponse contains the message identifier, request identifier, processed payload, metadata, and other necessary information.

      Parameters:
      requestId - The Message.identifier() that initiated the query. Used to associate the resulting QueryResponse with the original request. Must not be null.
      queryResponseMessage - The QueryResponseMessage to be converted into a QueryResponse. Must not be null.
      Returns:
      A QueryResponse representation of the provided QueryResponseMessage. It includes the identifier, metadata, and the serialized payload.
    • convertSubscriptionQueryMessage

      public static QueryMessage convertSubscriptionQueryMessage(@Nonnull io.axoniq.axonserver.grpc.query.SubscriptionQuery query)
      Converts a SubscriptionQuery into a QueryMessage. This method processes the given SubscriptionQuery by extracting its identifier, payload, metadata, and other necessary fields to construct a QueryMessage.
      Parameters:
      query - The SubscriptionQuery to be converted. Must not be null. The SubscriptionQuery should contain properly set payload, metadata, and response type details.
      Returns:
      A QueryMessage representation of the provided SubscriptionQuery. It includes the processed payload, metadata, and response type.
      Throws:
      NullPointerException - if the provided SubscriptionQuery is null.
    • convertQueryUpdate

      public static io.axoniq.axonserver.grpc.query.QueryUpdate convertQueryUpdate(@Nonnull SubscriptionQueryUpdateMessage update)
      Converts a SubscriptionQueryUpdateMessage into a QueryUpdate. This method processes the provided SubscriptionQueryUpdateMessage by extracting its payload, metadata, and other relevant details to construct a QueryUpdate. If the payload is unavailable, it defaults to an empty byte array.
      Parameters:
      update - The SubscriptionQueryUpdateMessage to be converted. Must not be null. The payload and metadata should be properly set in the provided update.
      Returns:
      A QueryUpdate representation of the given SubscriptionQueryUpdateMessage. It includes the extracted payload, metadata, and other necessary information.
      Throws:
      NullPointerException - if the provided SubscriptionQueryUpdateMessage is null.
    • convertQueryUpdate

      public static SubscriptionQueryUpdateMessage convertQueryUpdate(@Nonnull io.axoniq.axonserver.grpc.query.QueryUpdate queryUpdate)
      Converts a QueryUpdate object into a SubscriptionQueryUpdateMessage.
      Parameters:
      queryUpdate - The QueryUpdate object to be converted; must not be null.
      Returns:
      A SubscriptionQueryUpdateMessage created from the provided QueryUpdate.
    • convertQueryUpdate

      public static io.axoniq.axonserver.grpc.query.QueryUpdate convertQueryUpdate(String clientId, @Nullable ErrorCode errorCode, Throwable error)
      Converts error information and a client identifier into a QueryUpdate. This method creates a QueryUpdate containing the error message derived from the given Throwable along with the provided client identifier.
      Parameters:
      clientId - The identifier of the client associated with the error. Must not be null.
      errorCode - The error code identifying the type of action that resulted in an error, if known.
      error - The Throwable containing error details to be translated into an error message. Must not be null.
      Returns:
      A QueryUpdate containing the client identifier and an error message derived from the provided Throwable.