Class LocalShortcutQueryBusConnector

java.lang.Object
io.axoniq.framework.messaging.queryhandling.distributed.DelegatingQueryBusConnector
io.axoniq.framework.messaging.queryhandling.distributed.LocalShortcutQueryBusConnector
All Implemented Interfaces:
QueryBusConnector, DescribableComponent

public class LocalShortcutQueryBusConnector extends DelegatingQueryBusConnector
A QueryBusConnector that offers a "local shortcut".

This shortcut triggers for point-to-point queries matching a LocalQueryDispatchPredicate, and for which the local segment subscribed a handler, the query is handed to the local segment directly instead of being routed through the wrapped connector. Furthermore, the shortcut only activates when the local segment can actually handle the command, tracked through the subscribe(QualifiedName)/unsubscribe(QualifiedName) calls this connector observes.

Short-cut queries are handled through the same QueryBusConnector.Handler as any other QueryBusConnector. As such, they are queued onto and executed by the same bounded, priority-ordered worker pool as commands arriving from remote segments. A burst of locally-preferred commands is therefore subject to the same back-pressure and cannot flood the local segment beyond what it would already accept from remote traffic.

The shortcut applies to point-to-point queries only. Subscription queries are always routed through the wrapped connector, as their update registrations must be coordinated across all segments.

Since:
5.4.0
Author:
Allard Buijze
See Also:
  • Constructor Details

    • LocalShortcutQueryBusConnector

      public LocalShortcutQueryBusConnector(QueryBusConnector delegate, LocalQueryDispatchPredicate shortcutPredicate)
      Initialize a connector with the given delegate, using the given shortcutPredicate to decide whether to shortcut a query yes or no.
      Parameters:
      delegate - the QueryBusConnector to delegate to when not querying locally
      shortcutPredicate - the predicate deciding whether a query should be dispatched to the local segment directly
  • Method Details

    • query

      public MessageStream<QueryResponseMessage> query(QueryMessage query, @Nullable ProcessingContext context)
      Description copied from interface: QueryBusConnector
      Sends the given query to the remote QueryBus.
      Specified by:
      query in interface QueryBusConnector
      Overrides:
      query in class DelegatingQueryBusConnector
      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:
    • subscribe

      public CompletableFuture<Void> subscribe(QualifiedName name)
      Description copied from interface: QueryBusConnector
      Subscribes this connector to queries matching the given name.

      A connector serves queries of a given name with a single handler. Subscribing a name this connector is already subscribed to therefore has no further effect, and completes as soon as the subscription that is already in place is acknowledged. A single unsubscribe of that name undoes any number of subscriptions to it.

      Specified by:
      subscribe in interface QueryBusConnector
      Overrides:
      subscribe in class DelegatingQueryBusConnector
      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(QualifiedName name)
      Description copied from interface: QueryBusConnector
      Unsubscribes this connector from queries with the given name.

      Undoes any number of subscriptions to the given name, leaving no query of that name routed to this connector.

      Specified by:
      unsubscribe in interface QueryBusConnector
      Overrides:
      unsubscribe in class DelegatingQueryBusConnector
      Parameters:
      name - The QualifiedName of the Message.type() to unsubscribe from.
      Returns:
      true if unsubscribing was successful, false otherwise.
    • onIncomingQuery

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

      public void describeTo(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
      Overrides:
      describeTo in class DelegatingQueryBusConnector
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.