/** * Configures the given Transaction Manager to use in this configuration. The builder receives the Configuration as * input and is expected to return a fully initialized {@link TransactionManager} * instance. * * @param transactionManagerBuilder The builder function for the {@link TransactionManager} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureTransactionManager(Function<Configuration, TransactionManager> transactionManagerBuilder) { return registerComponent(TransactionManager.class, transactionManagerBuilder); }
/** * Configures the given Resource Injector to use for Sagas in this configuration. The builder receives the * Configuration as input and is expected to return a fully initialized {@link ResourceInjector} instance. * * @param resourceInjectorBuilder The builder function for the {@link ResourceInjector} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureResourceInjector(Function<Configuration, ResourceInjector> resourceInjectorBuilder) { return registerComponent(ResourceInjector.class, resourceInjectorBuilder); }
/** * Configures the given Command Bus to use in this configuration. The builder receives the Configuration as input * and is expected to return a fully initialized {@link CommandBus} * instance. * * @param commandBusBuilder The builder function for the {@link CommandBus} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureCommandBus(Function<Configuration, CommandBus> commandBusBuilder) { return registerComponent(CommandBus.class, commandBusBuilder); }
/** * Configures the given Event Store to use in this configuration. The builder receives the Configuration as input * and is expected to return a fully initialized {@link EventStore} * instance. * * @param eventStoreBuilder The builder function for the {@link EventStore} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureEventStore(Function<Configuration, EventStore> eventStoreBuilder) { return registerComponent(EventBus.class, eventStoreBuilder); }
/** * Configures the given Query Update Emitter to use in this configuration. The builder receives the Configuration as * input and is expected to return a fully initialized {@link QueryUpdateEmitter} instance. * * @param queryUpdateEmitterBuilder The builder function for the {@link QueryUpdateEmitter} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureQueryUpdateEmitter( Function<Configuration, QueryUpdateEmitter> queryUpdateEmitterBuilder) { return registerComponent(QueryUpdateEmitter.class, queryUpdateEmitterBuilder); }
/** * Configures the given Query Bus to use in this configuration. The builder receives the Configuration as input * and is expected to return a fully initialized {@link QueryBus} * instance. * * @param queryBusBuilder The builder function for the {@link QueryBus} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureQueryBus(Function<Configuration, QueryBus> queryBusBuilder) { return registerComponent(QueryBus.class, queryBusBuilder); }
/** * Configures the given Serializer to use in this configuration. The builder receives the Configuration as input * and is expected to return a fully initialized {@link Serializer} * instance. * * @param serializerBuilder The builder function for the {@link Serializer} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureSerializer(Function<Configuration, Serializer> serializerBuilder) { return registerComponent(Serializer.class, serializerBuilder); }
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { configurer.registerComponent(ApplicationContext.class, c -> applicationContext); } }
/** * Configures the given Event Bus to use in this configuration. The builder receives the Configuration as input * and is expected to return a fully initialized {@link EventBus} * instance. * <p> * Note that this builder should not be used when an Event Store is configured. Since Axon 3, the Event Store will * act as Event Bus implementation as well. * * @param eventBusBuilder The builder function for the {@link EventBus} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureEventBus(Function<Configuration, EventBus> eventBusBuilder) { return registerComponent(EventBus.class, eventBusBuilder); }
@Override public void configureModule(Configurer configurer) { configurer.registerComponent(AxonServerConfiguration.class, c -> new AxonServerConfiguration()); configurer.registerComponent(AxonServerConnectionManager.class, c -> buildAxonServerConnectionManager(c)); configurer.configureEventStore(this::buildEventStore); configurer.configureCommandBus(this::buildCommandBus); configurer.configureQueryBus(this::buildQueryBus); configurer.registerModule(new EventProcessorInfoConfiguration()); configurer.registerComponent(TokenStore.class, c -> { logger.warn("BEWARE! Falling back to an in-memory token store. It is highly recommended to configure a " + "persistent implementation, based on the activity of the handler."); return new InMemoryTokenStore(); }); }
configurer.registerComponent(ParameterResolverFactory.class, c -> beanFactory .getBean(parameterResolver.getBeanName(), ParameterResolverFactory.class)); messageSerializer -> configurer.configureMessageSerializer(c -> getBean(messageSerializer, c))); findComponent(TokenStore.class) .ifPresent(tokenStore -> configurer.registerComponent(TokenStore.class, c -> getBean(tokenStore, c))); try { findComponent(PlatformTransactionManager.class).ifPresent( .ifPresent(tm -> configurer.configureTransactionManager(c -> getBean(tm, c))); findComponent(SagaStore.class) .ifPresent(sagaStore -> configurer.registerComponent(SagaStore.class, c -> getBean(sagaStore, c))); findComponent(ListenerInvocationErrorHandler.class).ifPresent( handler -> configurer.registerComponent(ListenerInvocationErrorHandler.class, c -> getBean(handler, c)) ); findComponent(ErrorHandler.class).ifPresent( handler -> configurer.registerComponent(ErrorHandler.class, c -> getBean(handler, c)) ); .registerComponent(DeadlineManager.class, c -> getBean(deadlineManager, c)));
@Before public void setUp() { EventStore eventStore = spy(EmbeddedEventStore.builder() .storageEngine(new InMemoryEventStorageEngine()) .build()); Configurer configurer = DefaultConfigurer.defaultConfiguration(); configurer.eventProcessing() .usingSubscribingEventProcessors() .registerSaga(MySaga.class); configuration = configurer.configureEventStore(c -> eventStore) .configureAggregate(MyAggregate.class) .registerComponent(DeadlineManager.class, this::buildDeadlineManager) .start(); published = new CopyOnWriteArrayList<>(); configuration.eventBus().subscribe(msgs -> msgs.forEach(msg -> published.add(msg.getPayload()))); }
return new DefaultConfigurer() .registerComponent(EntityManagerProvider.class, c -> entityManagerProvider) .registerComponent(TransactionManager.class, c -> transactionManager) .configureEmbeddedEventStore( c -> JpaEventStorageEngine.builder() .build() .registerComponent(TokenStore.class, c -> JpaTokenStore.builder() .entityManagerProvider(c.getComponent(EntityManagerProvider.class)) .serializer(c.serializer()) .build()) .registerComponent(SagaStore.class, c -> JpaSagaStore.builder() .entityManagerProvider(c.getComponent(EntityManagerProvider.class))
@Test public void testStagedEventsLoadInCorrectOrder() { Configuration config = DefaultConfigurer.defaultConfiguration() .configureAggregate(TestAggregate.class) .registerCommandHandler(x -> new Handler()) .configureEmbeddedEventStore(x -> new InMemoryEventStorageEngine()) .registerComponent(List.class, c -> new CopyOnWriteArrayList()) .buildConfiguration(); config.start(); CommandGateway gw = config.commandGateway(); gw.sendAndWait(new Create("1")); gw.sendAndWait(new Test1()); gw.sendAndWait(new ShowItems("1", "from-eventstore")); config.shutdown(); assertEquals(asList("pre-rollback-first","pre-rollback-second", "post-rollback-first","post-rollback-second", "from-eventstore-first", "from-eventstore-second"), config.getComponent(List.class)); }
/** * Configures the given Resource Injector to use for Sagas in this configuration. The builder receives the * Configuration as input and is expected to return a fully initialized {@link ResourceInjector} instance. * * @param resourceInjectorBuilder The builder function for the {@link ResourceInjector} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureResourceInjector(Function<Configuration, ResourceInjector> resourceInjectorBuilder) { return registerComponent(ResourceInjector.class, resourceInjectorBuilder); }
/** * Configures the given Transaction Manager to use in this configuration. The builder receives the Configuration as * input and is expected to return a fully initialized {@link TransactionManager} * instance. * * @param transactionManagerBuilder The builder function for the {@link TransactionManager} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureTransactionManager(Function<Configuration, TransactionManager> transactionManagerBuilder) { return registerComponent(TransactionManager.class, transactionManagerBuilder); }
/** * Configures the given Query Update Emitter to use in this configuration. The builder receives the Configuration as * input and is expected to return a fully initialized {@link QueryUpdateEmitter} instance. * * @param queryUpdateEmitterBuilder The builder function for the {@link QueryUpdateEmitter} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureQueryUpdateEmitter( Function<Configuration, QueryUpdateEmitter> queryUpdateEmitterBuilder) { return registerComponent(QueryUpdateEmitter.class, queryUpdateEmitterBuilder); }
/** * Configures the given Command Bus to use in this configuration. The builder receives the Configuration as input * and is expected to return a fully initialized {@link CommandBus} * instance. * * @param commandBusBuilder The builder function for the {@link CommandBus} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureCommandBus(Function<Configuration, CommandBus> commandBusBuilder) { return registerComponent(CommandBus.class, commandBusBuilder); }
/** * Configures the given Query Bus to use in this configuration. The builder receives the Configuration as input * and is expected to return a fully initialized {@link QueryBus} * instance. * * @param queryBusBuilder The builder function for the {@link QueryBus} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureQueryBus(Function<Configuration, QueryBus> queryBusBuilder) { return registerComponent(QueryBus.class, queryBusBuilder); }
/** * Configures the given Query Bus to use in this configuration. The builder receives the Configuration as input * and is expected to return a fully initialized {@link QueryBus} * instance. * * @param queryBusBuilder The builder function for the {@link QueryBus} * @return the current instance of the Configurer, for chaining purposes */ default Configurer configureQueryBus(Function<Configuration, QueryBus> queryBusBuilder) { return registerComponent(QueryBus.class, queryBusBuilder); }