Class LocalShortcutQueryBusConnector
- All Implemented Interfaces:
QueryBusConnector,DescribableComponent
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.axoniq.framework.messaging.queryhandling.distributed.QueryBusConnector
QueryBusConnector.Handler, QueryBusConnector.UpdateCallback -
Field Summary
Fields inherited from class io.axoniq.framework.messaging.queryhandling.distributed.DelegatingQueryBusConnector
delegate -
Constructor Summary
ConstructorsConstructorDescriptionLocalShortcutQueryBusConnector(QueryBusConnector delegate, LocalQueryDispatchPredicate shortcutPredicate) Initialize a connector with the givendelegate, using the givenshortcutPredicateto decide whether to shortcut a query yes or no. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.voidonIncomingQuery(QueryBusConnector.Handler handler) Registers a handler to process incoming query messages.query(QueryMessage query, @Nullable ProcessingContext context) Sends the givenqueryto the remote QueryBus.subscribe(QualifiedName name) Subscribes this connector to queries matching the givenname.booleanunsubscribe(QualifiedName name) Unsubscribes this connector from queries with the givenname.Methods inherited from class io.axoniq.framework.messaging.queryhandling.distributed.DelegatingQueryBusConnector
subscriptionQuery
-
Constructor Details
-
LocalShortcutQueryBusConnector
public LocalShortcutQueryBusConnector(QueryBusConnector delegate, LocalQueryDispatchPredicate shortcutPredicate) Initialize a connector with the givendelegate, using the givenshortcutPredicateto decide whether to shortcut a query yes or no.- Parameters:
delegate- theQueryBusConnectorto delegate to when not querying locallyshortcutPredicate- 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:QueryBusConnectorSends the givenqueryto the remote QueryBus.- Specified by:
queryin interfaceQueryBusConnector- Overrides:
queryin classDelegatingQueryBusConnector- 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
Description copied from interface:QueryBusConnectorSubscribes this connector to queries matching the givenname.A connector serves queries of a given
namewith a single handler. Subscribing anamethis 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 singleunsubscribeof thatnameundoes any number of subscriptions to it.- Specified by:
subscribein interfaceQueryBusConnector- Overrides:
subscribein classDelegatingQueryBusConnector- Parameters:
name- TheQualifiedNameof theMessage.type()to subscribe to.- Returns:
- A
CompletableFuturethat completes successfully when this connector subscribed to the givenname.
-
unsubscribe
Description copied from interface:QueryBusConnectorUnsubscribes this connector from queries with the givenname.Undoes any number of
subscriptionsto the givenname, leaving no query of that name routed to this connector.- Specified by:
unsubscribein interfaceQueryBusConnector- Overrides:
unsubscribein classDelegatingQueryBusConnector- Parameters:
name- TheQualifiedNameof theMessage.type()to unsubscribe from.- Returns:
trueif unsubscribing was successful,falseotherwise.
-
onIncomingQuery
Description copied from interface:QueryBusConnectorRegisters a handler to process incoming query messages.- Specified by:
onIncomingQueryin interfaceQueryBusConnector- Overrides:
onIncomingQueryin classDelegatingQueryBusConnector- Parameters:
handler- The handler responsible for managing incoming queries.
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods 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
DescribableComponentimplementation 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 thedescribeTomethod, 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:
describeToin interfaceDescribableComponent- Overrides:
describeToin classDelegatingQueryBusConnector- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-