Class AxonServerQueryBusConnector

java.lang.Object
org.axonframework.axonserver.connector.query.AxonServerQueryBusConnector
All Implemented Interfaces:
DescribableComponent, QueryBusConnector

public class AxonServerQueryBusConnector extends Object implements QueryBusConnector
AxonServerQueryBusConnector is an implementation of QueryBusConnector that connects to AxonServer to enable the dispatching and receiving of queries. It manages the registration of handlers, query subscriptions, and disconnection from the AxonServer query bus.

This class facilitates interaction with AxonServer, handles incoming query requests, manages active subscriptions, and oversees lifecycle phases related to query dispatching and receiving.

Since:
5.0.0
Author:
Steven van Beelen, Allard Buijze, Jan Galinski
  • Constructor Details

    • AxonServerQueryBusConnector

      public AxonServerQueryBusConnector(@Nonnull io.axoniq.axonserver.connector.AxonServerConnection connection, @Nonnull AxonServerConfiguration configuration)
      Creates a QueryBusConnector implementation that connects to AxonServer for dispatching and receiving queries.
      Parameters:
      connection - The connection to AxonServer
      configuration - The configuration containing local settings for this connector
  • Method Details

    • start

      public void start()
      Starts the Axon Server QueryBusConnector implementation.
    • subscribe

      public CompletableFuture<Void> subscribe(@Nonnull QualifiedName name)
      Description copied from interface: QueryBusConnector
      Subscribes this connector to queries matching the given name.
      Specified by:
      subscribe in interface QueryBusConnector
      Parameters:
      name - The QualifiedName of the Message.type() to subscribe to.
      Returns:
      A CompletableFuture that completes successfully when this connector subscribed to the given name.
    • unsubscribe

      public boolean unsubscribe(@Nonnull QualifiedName name)
      Description copied from interface: QueryBusConnector
      Unsubscribes this connector from queries with the given name.
      Specified by:
      unsubscribe in interface QueryBusConnector
      Parameters:
      name - The QualifiedName of the Message.type() to unsubscribe from.
      Returns:
      true if unsubscribing was successful, false otherwise.
    • onIncomingQuery

      public void onIncomingQuery(@Nonnull QueryBusConnector.Handler handler)
      Description copied from interface: QueryBusConnector
      Registers a handler to process incoming query messages.
      Specified by:
      onIncomingQuery in interface QueryBusConnector
      Parameters:
      handler - The handler responsible for managing incoming queries.
    • query

      @Nonnull public MessageStream<QueryResponseMessage> query(@Nonnull QueryMessage query, @Nullable ProcessingContext context)
      Description copied from interface: QueryBusConnector
      Sends the given query to the remote QueryBus.
      Specified by:
      query in interface QueryBusConnector
      Parameters:
      query - The query to send to the remote QueryBus.
      context - The context, if available, in which the query is generated
      Returns:
      the stream of responses for the query
      See Also:
    • subscriptionQuery

      @Nonnull public MessageStream<QueryResponseMessage> subscriptionQuery(@Nonnull QueryMessage query, @Nullable ProcessingContext context, int updateBufferSize)
      Description copied from interface: QueryBusConnector
      Sends the given query to the remote QueryBus.
      Specified by:
      subscriptionQuery in interface QueryBusConnector
      Parameters:
      query - The query to send to the remote QueryBus.
      context - The context, if available, in which the query is generated
      updateBufferSize - The size of the buffer used to store update for the subscription query.
      Returns:
      the stream of responses for the query
      See Also:
    • disconnect

      public CompletableFuture<Void> disconnect()
      Disconnect the query bus for receiving queries from Axon Server, by unsubscribing all registered query handlers.

      This shutdown operation is performed in the Phase.INBOUND_QUERY_CONNECTOR phase.

      Returns:
      A completable future that resolves once the AxonServerConnection.queryChannel() has prepared disconnecting.
    • shutdownDispatching

      public CompletableFuture<Void> shutdownDispatching()
      Shutdown the query bus asynchronously for dispatching query to Axon Server.

      This process will wait for dispatched queries which have not received a response yet. This shutdown operation is performed in the Phase.OUTBOUND_QUERY_CONNECTORS phase.

      Returns:
      A completable future which is resolved once all query dispatching activities are completed.
    • describeTo

      public void describeTo(@Nonnull ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.