/** * Registers the given {@code beans} as event handlers with the Event Handler Configuration. The beans are sorted * (see {@link AnnotationAwareOrderComparator}) before registering them to the configuration. * * @param beans the beans to register */ public void setEventHandlers(List<Object> beans) { AnnotationAwareOrderComparator.sort(beans); beans.forEach(b -> eventProcessingConfigurer.registerEventHandler(c -> b)); }
/** * Registers a {@link Function} that builds an Event Handler instance. * * @param eventHandlerBuilder a {@link Function} that builds an Event Handler instance. * @return the current instance of the Configurer, for chaining purposes. */ default Configurer registerEventHandler(Function<Configuration, Object> eventHandlerBuilder) { eventProcessing().registerEventHandler(eventHandlerBuilder); return this; }
@Test public void testQueryHandlerAndEventHandlerCleanlyShutdown() { UserSummaryProjection userSummaryProjection = new UserSummaryProjection(); Configurer configurer = DefaultConfigurer.defaultConfiguration(); configurer.configureCommandBus(c -> SimpleCommandBus.builder().build()) .configureQueryBus(c -> SimpleQueryBus.builder().build()) .configureEmbeddedEventStore(c -> new InMemoryEventStorageEngine()) .registerQueryHandler(c -> userSummaryProjection); configurer.eventProcessing() .registerEventHandler(c -> userSummaryProjection); Configuration configuration = configurer.buildConfiguration(); configuration.start(); configuration.shutdown(); }