Class SagaConfigurer<T>
- Type Parameters:
T- the Saga type under configuration
- All Implemented Interfaces:
ComponentBuilder<EventHandlingComponent>
This configurer retains the Axon Framework 4 fluent configuration API while adapting it to Axon Framework 5 event
processing. It is a ComponentBuilder for the Saga's EventHandlingComponent, so it can be registered
declaratively on an event processor:
MessagingConfigurer.create()
.componentRegistry(cr -> cr.registerComponent(SagaStore.class, c -> new InMemorySagaStore()))
.eventProcessing(processing -> processing.subscribing(
subscribing -> subscribing.defaultProcessor(
"orders",
components -> components.declarative(
"Saga[OrderSaga]",
SagaConfigurer.forType(OrderSaga.class)))));
The first call to build(Configuration) fixes this configurer's settings. Further configuration is rejected,
and repeated build calls return the same manager, matching the lifecycle of the Axon Framework 4 configurer. A
configurer is therefore single-use and stays bound to the Configuration it was first built with: building it
a second time returns the manager assembled from the first, ignoring the Configuration passed in. Register a
separate configurer per Saga type, as Axon Framework 4's SagaConfigurer#initialize(Configuration) required.
The built manager registers itself with the configuration's LegacyScopeAwareProvider, so that the deadlines
its Sagas schedule are delivered to it.
A custom manager replaces the complete default assembly. A custom repository replaces the default repository and its store dependency. Consequently, lower-level settings are only used when this configurer builds that level.
- Since:
- 4.0
- Author:
- Allard Buijze, Mateusz Nowak
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSagaConfigurer(Class<T> type) Initializes a configurer for the given Saga type. -
Method Summary
Modifier and TypeMethodDescriptionbuild(Configuration configuration) Builds the Saga manager for this configuration.configureRepository(Function<Configuration, SagaRepository<T>> repositoryBuilder) Configures the Saga repository.configureSagaFactory(Supplier<T> sagaFactory) Configures the factory used by the default annotated Saga manager to create Saga instances.configureSagaManager(Function<Configuration, AbstractSagaManager<T>> managerBuilder) Configures the Saga manager.configureSagaStore(Function<Configuration, SagaStore<? super T>> storeBuilder) Configures the store used by the default Saga repository.static <T> SagaConfigurer<T> Retrieves a configurer for the givensagaType.
-
Constructor Details
-
SagaConfigurer
Initializes a configurer for the given Saga type.- Parameters:
type- the type of Saga to configure
-
-
Method Details
-
forType
Retrieves a configurer for the givensagaType.- Type Parameters:
T- the Saga type under configuration- Parameters:
sagaType- the type of Saga to configure- Returns:
- a configurer for the given
sagaType
-
configureSagaManager
public SagaConfigurer<T> configureSagaManager(Function<Configuration, AbstractSagaManager<T>> managerBuilder) Configures the Saga manager. Supplying a manager makes that builder responsible for the complete manager assembly; configured repositories, stores, and Saga factories are not used.- Parameters:
managerBuilder- the function that builds the Saga manager- Returns:
- this configurer for fluent configuration
-
configureRepository
public SagaConfigurer<T> configureRepository(Function<Configuration, SagaRepository<T>> repositoryBuilder) Configures the Saga repository. Supplying a repository makes that builder responsible for its store; a separately configured Saga store is not used by the default manager.- Parameters:
repositoryBuilder- the function that builds the Saga repository- Returns:
- this configurer for fluent configuration
-
configureSagaStore
public SagaConfigurer<T> configureSagaStore(Function<Configuration, SagaStore<? super T>> storeBuilder) Configures the store used by the default Saga repository.Without this setting the default repository resolves the
SagaStoreregistered as a component. Unlike Axon Framework 4, which silently fell back to an in-memory store, building fails when neither is available: a Saga has to be told where it is stored.- Parameters:
storeBuilder- the function that builds the Saga store- Returns:
- this configurer for fluent configuration
-
configureSagaFactory
Configures the factory used by the default annotated Saga manager to create Saga instances.Use this when a Saga has no accessible no-argument constructor or needs a collaborator that cannot be provided as a handler method parameter.
- Parameters:
sagaFactory- the factory that creates Saga instances- Returns:
- this configurer for fluent configuration
-
build
Builds the Saga manager for this configuration. The first invocation fixes the configured builders; subsequent invocations return the same manager, ignoring theconfigurationgiven to them.The first invocation also registers the manager with the configuration's
LegacyScopeAwareProvider, if the configuration'sScopeAwareProvideris one, so that deadlines the Sagas schedule reach the manager.The configured builders are fixed before the manager is assembled, so a configurer whose assembly failed stays fixed and cannot be reconfigured. This mirrors Axon Framework 4, where
initialize(Configuration)likewise fixed the configurer before the manager, repository, and store components were resolved.- Specified by:
buildin interfaceComponentBuilder<T>- Parameters:
configuration- the configuration providing shared framework components- Returns:
- the Saga manager built by this configurer
- Throws:
AxonConfigurationException- if the default repository is used and noSagaStorewas configured throughconfigureSagaStore(Function)or registered as a component
-