@Override public void start() { config.start(); this.running = true; }
private AxonServerEventStore buildEventStore(Configuration c) { return AxonServerEventStore.builder() .configuration(c.getComponent(AxonServerConfiguration.class)) .platformConnectionManager(c.getComponent(AxonServerConnectionManager.class)) .snapshotSerializer(c.serializer()) .eventSerializer(c.eventSerializer()) .upcasterChain(c.upcasterChain()) .build(); }
@Override public Configurer registerCommandHandler(int phase, Function<Configuration, Object> annotatedCommandHandlerBuilder) { startHandlers.add(new RunnableHandler(phase, () -> { Object handler = annotatedCommandHandlerBuilder.apply(config); Assert.notNull(handler, () -> "annotatedCommandHandler may not be null"); Registration registration = new AnnotationCommandHandlerAdapter(handler, config.parameterResolverFactory(), config.handlerDefinition(handler.getClass())) .subscribe(config.commandBus()); shutdownHandlers.add(new RunnableHandler(phase, registration::cancel)); })); return this; }
private AxonServerCommandBus buildCommandBus(Configuration c) { AxonServerCommandBus commandBus = new AxonServerCommandBus(c.getComponent(AxonServerConnectionManager.class), c.getComponent(AxonServerConfiguration.class), SimpleCommandBus.builder().build(), c.messageSerializer(), c.getComponent(RoutingStrategy.class, AnnotationRoutingStrategy::new), c.getComponent(CommandPriorityCalculator.class, () -> new CommandPriorityCalculator() {})); c.onShutdown(commandBus::disconnect); return commandBus; }
private AxonServerConnectionManager buildAxonServerConnectionManager(Configuration c) { AxonServerConnectionManager axonServerConnectionManager = new AxonServerConnectionManager(c.getComponent( AxonServerConfiguration.class)); c.onShutdown(axonServerConnectionManager::shutdown); return axonServerConnectionManager; }
@SuppressWarnings("unchecked") private EventProcessor defaultEventProcessor(String name, Configuration conf, EventHandlerInvoker eventHandlerInvoker) { if (conf.eventBus() instanceof StreamableMessageSource) { return trackingEventProcessor(name, eventHandlerInvoker, conf.getComponent( TrackingEventProcessorConfiguration.class, TrackingEventProcessorConfiguration::forSingleThreadedProcessing), (StreamableMessageSource) conf.eventBus()); } else { return subscribingEventProcessor(name, conf, eventHandlerInvoker, Configuration::eventBus); } }
c -> c.getComponent( AggregateMetaModelFactory.class, () -> new AnnotatedAggregateMetaModelFactory(c.parameterResolverFactory(), c.handlerDefinition(aggregate)) ).createModel(aggregate)); commandTargetResolver = new Component<>(() -> parent, name("commandTargetResolver"), c -> c.getComponent(CommandTargetResolver.class, AnnotationCommandTargetResolver::new)); snapshotTriggerDefinition = new Component<>(() -> parent, name("snapshotTriggerDefinition"), "Repository<" + aggregate.getSimpleName() + ">", c -> { state(c.eventBus() instanceof EventStore, () -> "Default configuration requires the use of event sourcing. Either configure an Event " + "Store to use, or configure a specific repository implementation for " + aggregate.toString()); if (c.commandBus() instanceof DisruptorCommandBus) { return ((DisruptorCommandBus) c.commandBus()).createRepository(c.eventStore(), aggregateFactory.get(), snapshotTriggerDefinition.get(), c.parameterResolverFactory(), c.handlerDefinition(aggregate), c::repository); .aggregateModel(metaModel.get()) .aggregateFactory(aggregateFactory.get()) .eventStore(c.eventStore()) .snapshotTriggerDefinition(snapshotTriggerDefinition.get())
private QueryBus buildQueryBus(Configuration c) { SimpleQueryBus localSegment = SimpleQueryBus.builder() .transactionManager(c.getComponent(TransactionManager.class, NoTransactionManager::instance)) .errorHandler(c.getComponent(QueryInvocationErrorHandler.class, () -> LoggingQueryInvocationErrorHandler.builder().build())) .queryUpdateEmitter(c.queryUpdateEmitter()) .messageMonitor(c.messageMonitor(QueryBus.class, "localQueryBus")) .build(); AxonServerQueryBus queryBus = new AxonServerQueryBus(c.getComponent(AxonServerConnectionManager.class), c.getComponent(AxonServerConfiguration.class), c.queryUpdateEmitter(), localSegment, c.messageSerializer(), c.serializer(), c.getComponent(QueryPriorityCalculator.class, () -> new QueryPriorityCalculator() {})); c.onShutdown(queryBus::disconnect); return queryBus; }
/** * Provides the default CommandBus implementation. Subclasses may override this method to provide their own default. * * @param config The configuration based on which the component is initialized. * @return The default CommandBus to use. */ protected CommandBus defaultCommandBus(Configuration config) { SimpleCommandBus commandBus = SimpleCommandBus.builder() .transactionManager(config.getComponent(TransactionManager.class, () -> NoTransactionManager.INSTANCE)) .messageMonitor(config.messageMonitor(SimpleCommandBus.class, "commandBus")) .build(); commandBus.registerHandlerInterceptor(new CorrelationDataInterceptor<>(config.correlationDataProviders())); return commandBus; }
@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)); }
aggregateConf.configureRepository( c -> GenericJpaRepository.builder(aggregateType) .parameterResolverFactory(c.parameterResolverFactory()) .handlerDefinition(c.handlerDefinition(aggregateType)) .lockFactory(c.getComponent( LockFactory.class, () -> NullLockFactory.INSTANCE )) .entityManagerProvider(c.getComponent( EntityManagerProvider.class, () -> beanFactory.getBean(EntityManagerProvider.class) )) .eventBus(c.eventBus()) .repositoryProvider(c::repository) .build());
/** * Retrieves the Event Bus defined in this Configuration. * * @return the Event Bus defined in this Configuration */ default EventBus eventBus() { return getComponent(EventBus.class); }
@Before public void setUp() { Configuration configuration = DefaultConfigurer.defaultConfiguration() .configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine()) .configureAggregate(StubAggregate.class) .buildConfiguration(); configuration.start(); commandGateway = configuration.commandGateway(); }
.sagaType(configurer.type) .sagaStore(store.get()) .resourceInjector(c.resourceInjector()) .parameterResolverFactory(c.parameterResolverFactory()) .handlerDefinition(c.handlerDefinition(configurer.type)) .build(); if (managerBuilder == null) { managerBuilder = c -> { EventProcessingConfiguration eventProcessingConfiguration = c.eventProcessingConfiguration(); return AnnotatedSagaManager.<S>builder() .sagaType(configurer.type) .sagaRepository(repository.get()) .parameterResolverFactory(c.parameterResolverFactory()) .handlerDefinition(c.handlerDefinition(configurer.type)) .listenerInvocationErrorHandler(eventProcessingConfiguration.listenerInvocationErrorHandler( processingGroup()))
/** * Provides the default QueryBus implementations. Subclasses may override this method to provide their own default. * * @param config The configuration based on which the component is initialized. * @return The default QueryBus to use. */ protected QueryBus defaultQueryBus(Configuration config) { return SimpleQueryBus.builder() .messageMonitor(config.messageMonitor(SimpleQueryBus.class, "queryBus")) .transactionManager(config.getComponent(TransactionManager.class, NoTransactionManager::instance)) .errorHandler(config.getComponent( QueryInvocationErrorHandler.class, () -> LoggingQueryInvocationErrorHandler.builder().build() )) .queryUpdateEmitter(config.getComponent(QueryUpdateEmitter.class)) .build(); }
@Override public <M extends Message<?>> MessageMonitor<? super M> messageMonitor(Class<?> componentType, String componentName) { return config.messageMonitor(componentType, componentName); }
@Override public EventBus eventBus() { return config.eventBus(); }
@Before public void setUp() { configuration = DefaultConfigurer.defaultConfiguration() .configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine()) .configureAggregate(AggregateConfigurer.defaultConfiguration(MyAggregate.class) .configureAggregateFactory(c -> new AggregateFactory<MyAggregate>() { @Override public MyAggregate createAggregateRoot(String aggregateIdentifier, DomainEventMessage<?> firstEvent) { return new MyAggregate(aggregateIdentifier); } @Override public Class<MyAggregate> getAggregateType() { return MyAggregate.class; } })) .registerCommandHandler(c -> new MyCommandHandler(c.repository(MyAggregate.class), c.commandGateway())) .buildConfiguration(); configuration.start(); command = new MyCommand("outer", aggregateIdentifier, new MyCommand("middle", aggregateIdentifier, new MyCommand("inner", aggregateIdentifier))); }
@SneakyThrows public static void disabledMain(String[] args) { final Configuration configuration = DefaultConfigurer.defaultConfiguration() .configureAggregate(Entrance.class) .configureAggregate(Guest.class) .configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine()) .configureCommandBus(c -> new AsynchronousCommandBus()) .buildConfiguration(); configuration.start(); final CommandBus commandBus = configuration.commandBus(); commandBus.dispatch(asCommandMessage(new RegisterEntranceCommand("main"))); commandBus.dispatch(asCommandMessage(new UnlockEntranceCommand("main"))); commandBus.dispatch(asCommandMessage(new UnregisterEntranceCommand("main")) ); TimeUnit.SECONDS.sleep(1L); } }
@Override public CommandBus commandBus() { return config.commandBus(); }