Class MultiTenantAxonServerCommandBusConnector
- All Implemented Interfaces:
ConnectorLifecycle,CommandBusConnector,MultiTenantAwareComponent,DescribableComponent
CommandBusConnector.
The connector composes one AxonServerCommandBusConnector per TenantDescriptor, each owning its own
Axon Server connection, command handler subscriptions, and in-flight command tracking. Command subscription state and
the incoming-command handler are replayed onto newly registered tenants.
Internal, because the connector is wired by
AxonServerMultiTenancyConfigurationDefaults and
reached through the CommandBusConnector component, never constructed by an application itself.
- Since:
- 5.3.0
- Author:
- Jan Galinski, Jakob Hatzl
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.axoniq.framework.messaging.commandhandling.distributed.CommandBusConnector
CommandBusConnector.Handler, CommandBusConnector.ResultCallback -
Constructor Summary
ConstructorsConstructorDescriptionMultiTenantAxonServerCommandBusConnector(TenantRouter tenantRouter, AxonServerConnectionManager connectionManager, AxonServerConfiguration configuration, MessageConverter converter) Constructs aMultiTenantAxonServerCommandBusConnector. -
Method Summary
Modifier and TypeMethodDescriptionvoiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.Disconnects the connector.dispatch(CommandMessage command, @Nullable ProcessingContext processingContext) Resolves the connector of the tenant the givencommandbelongs to and dispatches the command to it.voidRegisters a handler that will be called when an incoming command is received.registerAndStartTenant(TenantDescriptor tenantDescriptor) Registers the giventenantDescriptoras a known tenant with this multi-tenant aware component.registerTenant(TenantDescriptor tenantDescriptor) Registers the giventenantDescriptoras a known tenant with this multi-tenant aware component.Shuts down the connector gracefully.voidstart()Starts the connector.subscribe(QualifiedName commandName, int loadFactor) Subscribes to a command on each tenant-specific connector with the givencommandNameand aloadFactor.booleanunsubscribe(QualifiedName commandName) Unsubscribes from a command with the givencommandNamefrom each tenant-specific connector.
-
Constructor Details
-
MultiTenantAxonServerCommandBusConnector
public MultiTenantAxonServerCommandBusConnector(TenantRouter tenantRouter, AxonServerConnectionManager connectionManager, AxonServerConfiguration configuration, MessageConverter converter) Constructs aMultiTenantAxonServerCommandBusConnector.- Parameters:
tenantRouter- the router deciding which tenant a dispatchedCommandMessageis routed toconnectionManager- the manager used to obtain theAxonServerConnectionfor a given tenantconfiguration- the configuration applied to each per-tenantAxonServerCommandBusConnectorconverter- theMessageConverterused by each per-tenantAxonServerCommandBusConnector
-
-
Method Details
-
start
public void start()Description copied from interface:ConnectorLifecycleStarts the connector.- Specified by:
startin interfaceConnectorLifecycle
-
dispatch
public CompletableFuture<CommandResultMessage> dispatch(CommandMessage command, @Nullable ProcessingContext processingContext) Resolves the connector of the tenant the givencommandbelongs to and dispatches the command to it.- Specified by:
dispatchin interfaceCommandBusConnector- Parameters:
command- the command message to dispatchprocessingContext- the processing context for the command- Returns:
- a
CompletableFuturethat will complete with the result of the command handling
-
subscribe
Subscribes to a command on each tenant-specific connector with the givencommandNameand aloadFactor.The
MultiTenantAxonServerCommandBusConnectorkeeps track of all known subscriptions and replays them on tenants dynamically added at runtime.- Specified by:
subscribein interfaceCommandBusConnector- Parameters:
commandName- theQualifiedNameof the command to subscribe toloadFactor- the load factor for the command, which can be used to control the distribution of command handling across multiple instances; should be a positive integer- Returns:
- a
CompletableFuturethat completes successfully when this connector subscribed to the givencommandNamewith the givenloadFactor
-
unsubscribe
Unsubscribes from a command with the givencommandNamefrom each tenant-specific connector.- Specified by:
unsubscribein interfaceCommandBusConnector- Parameters:
commandName- theQualifiedNameof the command to unsubscribe from- Returns:
trueif the unsubscription was successful,falseotherwise
-
onIncomingCommand
Registers a handler that will be called when an incoming command is received. The handler should process the command and call the providedResultCallbackto indicate success or failure.The handler is registered for each tenant-specific connection to make sure incoming commands from each tenant trigger the handling.
- Specified by:
onIncomingCommandin interfaceCommandBusConnector- Parameters:
handler- aBiConsumerthat takes aCommandMessageand aCommandBusConnector.ResultCallback
-
shutdownDispatching
Description copied from interface:ConnectorLifecycleShuts down the connector gracefully.- Specified by:
shutdownDispatchingin interfaceConnectorLifecycle- Returns:
- a
CompletableFuturethat completes when the connector has been shutdown.
-
disconnect
Description copied from interface:ConnectorLifecycleDisconnects the connector.- Specified by:
disconnectin interfaceConnectorLifecycle- Returns:
- a
CompletableFuturethat completes when the connector has been disconnected.
-
registerTenant
Description copied from interface:MultiTenantAwareComponentRegisters the giventenantDescriptoras a known tenant with this multi-tenant aware component.The caller must retain the returned
Registrationand cancel it when the tenant is removed, since releasing the component's per-tenant resources rides on that cancellation.- Specified by:
registerTenantin interfaceMultiTenantAwareComponent- Parameters:
tenantDescriptor- TheTenantDescriptorto register with this component.- Returns:
- A
Registrationused to deregister the giventenantDescriptor.
-
registerAndStartTenant
Description copied from interface:MultiTenantAwareComponentRegisters the giventenantDescriptoras a known tenant with this multi-tenant aware component. If applicable, this task will construct a tenant segment and start it.- Specified by:
registerAndStartTenantin interfaceMultiTenantAwareComponent- Parameters:
tenantDescriptor- TheTenantDescriptorto register with this component.- Returns:
- A
Registrationused to deregister the giventenantDescriptor.
-
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- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-