@Bean @ConditionalOnMissingBean({EventStorageEngine.class, EventBus.class}) public SimpleEventBus eventBus(AxonConfiguration configuration) { return SimpleEventBus.builder() .messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore")) .build(); }
/** * Provides the default EventBus 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 EventBus to use. */ protected EventBus defaultEventBus(Configuration config) { return SimpleEventBus.builder() .messageMonitor(config.messageMonitor(EventBus.class, "eventBus")) .build(); }
@Bean public EventBus eventBus() { return SimpleEventBus.builder().build(); }
/** * Creates an instance of the AnnotatedSagaTestFixture to test sagas of the given {@code sagaType}. * * @param sagaType The type of saga under test */ @SuppressWarnings({"unchecked"}) public SagaTestFixture(Class<T> sagaType) { this.sagaType = sagaType; eventScheduler = new StubEventScheduler(); deadlineManager = new StubDeadlineManager(); eventBus = SimpleEventBus.builder().build(); sagaStore = new InMemorySagaStore(); registeredResources.add(eventBus); commandBus = new RecordingCommandBus(); registeredResources.add(commandBus); registeredResources.add(eventScheduler); registeredResources.add(deadlineManager); registeredResources.add(DefaultCommandGateway.builder().commandBus(commandBus).build()); fixtureExecutionResult = new FixtureExecutionResultImpl<>(sagaStore, eventScheduler, deadlineManager, eventBus, commandBus, sagaType, fieldFilters); handlerDefinition = ClasspathHandlerDefinition.forClass(sagaType); }
@Test public void testCommandsAreRoutedToCorrectEntity() throws Exception { AggregateModel<Book> bookAggregateModel = AnnotatedAggregateMetaModelFactory.inspectAggregate(Book.class); EventBus mockEventBus = SimpleEventBus.builder().build(); mockEventBus.subscribe(m -> m.forEach(i -> System.out.println(i.getPayloadType().getName()))); AnnotatedAggregate<Book> bookAggregate = AnnotatedAggregate.initialize((Book) null, bookAggregateModel, mockEventBus); bookAggregate.handle(command(new CreateBookCommand("book1"))); bookAggregate.handle(command(new CreatePageCommand("book1"))); bookAggregate.handle(command(new CreateParagraphCommand("book1", 0))); bookAggregate.handle(command(new CreateParagraphCommand("book1", 0))); bookAggregate.handle(command(new UpdateParagraphCommand("book1", 0, 0, "Hello world"))); bookAggregate.handle(command(new UpdateParagraphCommand("book1", 0, 1, "Hello world2"))); assertEquals("Hello world", bookAggregate.getAggregateRoot().getPages().get(0).getParagraphs().get(0).getText()); assertEquals("Hello world2", bookAggregate.getAggregateRoot().getPages().get(0).getParagraphs().get(1).getText()); }
@Bean @ConditionalOnMissingBean({EventStorageEngine.class, EventBus.class}) public SimpleEventBus eventBus(AxonConfiguration configuration) { return SimpleEventBus.builder() .messageMonitor(configuration.messageMonitor(EventStore.class, "eventStore")) .build(); }
/** * Provides the default EventBus 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 EventBus to use. */ protected EventBus defaultEventBus(Configuration config) { return SimpleEventBus.builder() .messageMonitor(config.messageMonitor(EventBus.class, "eventBus")) .build(); }