MainDispatcher
Abstract base class for message dispatchers that manage multiple aggregate dispatchers.
This class coordinates the dispatching of messages to multiple named aggregates by creating individual dispatchers for each aggregate and managing their lifecycle. It provides a framework for implementing dispatchers that need to handle messages across different aggregates, ensuring proper initialization, starting, and graceful shutdown.
Subclasses must implement the abstract methods to define how messages are received for each aggregate and how individual aggregate dispatchers are created.
Example usage:
class MyMainDispatcher : MainDispatcher<MyMessage>() {
override val namedAggregates = setOf(myAggregate1, myAggregate2)
override fun receiveMessage(namedAggregate: NamedAggregate): Flux<MyMessage> {
// Implementation to receive messages for the aggregate
return myMessageFlux
}
override fun newAggregateDispatcher(
namedAggregate: NamedAggregate,
messageFlux: Flux<MyMessage>
): MessageDispatcher {
// Implementation to create dispatcher for the aggregate
return MyAggregateDispatcher(namedAggregate, messageFlux)
}
}
val dispatcher = MyMainDispatcher()
dispatcher.start()
// ... application logic ...
dispatcher.stopGracefully().block()Parameters
The type of message being dispatched, must be a non-null type.
See also
Inheritors
Functions
Creates a new message dispatcher for a specific named aggregate.
Creates a flux of messages for the specified named aggregate.
Stops the dispatcher gracefully by shutting down all aggregate dispatchers.