/** * Register a subscribing processor with given {@code name} that subscribes to the Event Bus. * * @param name The name of the Event Processor * @return this EventHandlingConfiguration instance for further configuration * @deprecated use {@link EventProcessingConfiguration#registerSubscribingEventProcessor(String)} instead */ @SuppressWarnings("UnusedReturnValue") @Deprecated public EventHandlingConfiguration registerSubscribingEventProcessor(String name) { return registerSubscribingEventProcessor(name, Configuration::eventBus); }
@Autowired public void configure(EventHandlingConfiguration config) { log.info("Configured tracking processors"); config.usingTrackingProcessors(); }
/** * Configures a rule to assign Event Handler beans that match the given {@code criteria} to the Processing Group * with given {@code name}, with neutral priority (value 0). * <p> * Note that, when beans match multiple criteria for different Processing Groups with equal priority, the outcome is * undefined. * * @param processingGroup The name of the Processing Group to assign matching Event Handlers to * @param criteria The criteria for Event Handler to match * @return this EventHandlingConfiguration instance for further configuration */ @SuppressWarnings("UnusedReturnValue") public EventHandlingConfiguration assignHandlersMatching(String processingGroup, Predicate<Object> criteria) { return assignHandlersMatching(processingGroup, 0, criteria); }
/** * Configure the use of Tracking Event Processors, instead of the default Subscribing ones. Tracking processors * work in their own thread(s), making processing asynchronous from the publication process. * <p> * The processor will use the {@link TokenStore} implementation provided in the global Configuration, and will * default to an {@link InMemoryTokenStore} when no Token Store was defined. Note that it is not recommended to use * the in-memory TokenStore in a production environment. * * @param config The configuration for the processors to use * @param sequencingPolicy The policy for processing events sequentially * @return this EventHandlingConfiguration instance for further configuration * @deprecated use {@link EventProcessingConfiguration#usingTrackingProcessors(Function)} instead */ @Deprecated public EventHandlingConfiguration usingTrackingProcessors( Function<Configuration, TrackingEventProcessorConfiguration> config, Function<Configuration, SequencingPolicy<? super EventMessage<?>>> sequencingPolicy) { return registerEventProcessorFactory( (conf, name, handlers) -> buildTrackingEventProcessor(conf, name, handlers, config, Configuration::eventBus, sequencingPolicy)); }
ApplicationContext applicationContext) { EventHandlingConfiguration queryModelConfiguration = new EventHandlingConfiguration().registerSubscribingEventProcessor("queryModel"); EventHandlingConfiguration commandPublisherConfiguration = new EventHandlingConfiguration().registerSubscribingEventProcessor("commandPublishingEventHandlers"); commandPublisherConfiguration.registerEventHandler(conf -> value); } else { queryModelConfiguration.registerEventHandler(conf -> value);
private EventProcessor buildTrackingEventProcessor(Configuration conf, String name, List<?> handlers, Function<Configuration, TrackingEventProcessorConfiguration> config, Function<Configuration, StreamableMessageSource<TrackedEventMessage<?>>> source, Function<Configuration, SequencingPolicy<? super EventMessage<?>>> sequencingPolicy) { return new TrackingEventProcessor(name, new SimpleEventHandlerInvoker(handlers, conf.parameterResolverFactory(), getListenerInvocationErrorHandler(conf, name), sequencingPolicy.apply(conf)), source.apply(conf), tokenStore.getOrDefault( name, c -> c.getComponent(TokenStore.class, InMemoryTokenStore::new) ).apply(conf), conf.getComponent(TransactionManager.class, NoTransactionManager::instance), getMessageMonitor(conf, EventProcessor.class, name), RollbackConfigurationType.ANY_THROWABLE, getErrorHandler(conf, name), config.apply(conf)); }
/** * Registers the Processing Group name to assign Event Handler beans to when no other, more explicit, rule matches * and no {@link ProcessingGroup} annotation is found. * * @param processingGroup The name of the Processing Group to assign Event Handlers to * @return this EventHandlingConfiguration instance for further configuration */ public EventHandlingConfiguration byDefaultAssignTo(String processingGroup) { return byDefaultAssignTo((object) -> processingGroup); }
/** * Configures the builder function to create the Message Monitor for the {@link EventProcessor} of the given name. * This overrides any Message Monitor configured through {@link Configurer}. * * @param name The name of the event processor * @param messageMonitorBuilder The builder function to use * @return this EventHandlingConfiguration instance for further configuration * @deprecated use {@link EventProcessingConfiguration#configureMessageMonitor(String, Function)} instead */ @Deprecated public EventHandlingConfiguration configureMessageMonitor(String name, Function<Configuration, MessageMonitor<Message<?>>> messageMonitorBuilder) { return configureMessageMonitor( name, (configuration, componentType, componentName) -> messageMonitorBuilder.apply(configuration) ); }
/** * Allows for more fine-grained definition of the Event Processor to use for each group of Event Listeners. The * given builder is expected to create a fully initialized Event Processor implementation based on the name and * list of event handler beans. The builder also received the global configuration instance, from which it can * retrieve components. * <p> * Note that the processor must be initialized, but shouldn't be started yet. The processor's * {@link EventProcessor#start()} method is invoked when the global configuration is started. * * @param eventProcessorBuilder The builder function for the Event Processor * @return this EventHandlingConfiguration instance for further configuration * @deprecated use {@link EventProcessingConfiguration#registerEventProcessorFactory(EventProcessingConfiguration.EventProcessorBuilder)} * instead */ @Deprecated public EventHandlingConfiguration registerEventProcessorFactory(EventProcessorBuilder eventProcessorBuilder) { onInit.add(conf -> conf.eventProcessingConfiguration() .registerEventProcessorFactory( (name, config, eventHandlerInvoker) -> buildEventProcessor(name, config, (MultiEventHandlerInvoker) eventHandlerInvoker, eventProcessorBuilder))); return this; }
/** * Registers a TrackingProcessor with the given {@code name}, reading from the given {@code source} and using the * given {@code processorConfiguration}. The given {@code sequencingPolicy} defines the policy for events that need * to be executed sequentially. * * @param name The name of the Tracking Processor * @param source The source to read Events from * @param processorConfiguration The configuration for the processor * @param sequencingPolicy The sequencing policy to apply when processing events in parallel * @return this EventHandlingConfiguration instance for further configuration * @deprecated use {@link EventProcessingConfiguration#registerTrackingEventProcessor(String, Function, Function)} instead */ @Deprecated public EventHandlingConfiguration registerTrackingProcessor(String name, Function<Configuration, StreamableMessageSource<TrackedEventMessage<?>>> source, Function<Configuration, TrackingEventProcessorConfiguration> processorConfiguration, Function<Configuration, SequencingPolicy<? super EventMessage<?>>> sequencingPolicy) { eventProcessorBuilders.put(name, (conf, handlers) -> conf.eventProcessingConfiguration() .registerEventProcessor(name, (n, c, ehi) -> buildTrackingEventProcessor(c, n, handlers, processorConfiguration, source, sequencingPolicy))); return this; }
@Autowired public void configure(EventHandlingConfiguration config, DefaultSubscribableEventSource source) { final String packageName = NotificationLoggingListener.class.getPackage().getName(); log.info("Register event processor {} for {}", source.getClass(), packageName); config.registerSubscribingEventProcessor(packageName, c -> source); }
/** * Configure the use of Tracking Event Processors, instead of the default Subscribing ones. Tracking processors * work in their own thread(s), making processing asynchronous from the publication process. * <p> * The processor will use the {@link TokenStore} implementation provided in the global Configuration, and will * default to an {@link InMemoryTokenStore} when no Token Store was defined. Note that it is not recommended to use * the in-memory TokenStore in a production environment. * <p> * The processors will use the a {@link TrackingEventProcessorConfiguration} registered with the configuration, or * otherwise to a single threaded configuration (which means the processor will run in a single Thread and a batch * size of 1). * * @return this EventHandlingConfiguration instance for further configuration * @deprecated use {@link EventProcessingConfiguration#usingTrackingProcessors()} instead */ @Deprecated public EventHandlingConfiguration usingTrackingProcessors() { return usingTrackingProcessors(c -> c.getComponent(TrackingEventProcessorConfiguration.class, TrackingEventProcessorConfiguration::forSingleThreadedProcessing), c -> SequentialPerAggregatePolicy.instance()); }