public EventProcessor getEventProcessor(String processorName){ return this.eventProcessingConfiguration .eventProcessor(processorName) .orElseThrow(() -> new RuntimeException("Processor not found")); }
/** * Obtains an {@link EventProcessor} through the given {@code name}. * * @param name a {@link String} specifying the name of an {@link EventProcessor} * @param <T> the type of the expected {@link EventProcessor} * @return an {@link Optional} specifying whether an {@link EventProcessor} with the given {@code name} exists */ @SuppressWarnings("unchecked") default <T extends EventProcessor> Optional<T> eventProcessor(String name) { return (Optional<T>) Optional.ofNullable(eventProcessors().get(name)); }
/** * Obtains an Saga {@link EventProcessor} implementation for the given {@code sagaType}. * * @param sagaType the type of Saga for which to get the Event Processor * @param <T> the type of the expected {@link EventProcessor} * @return an {@link Optional} specifying whether an {@link EventProcessor} for the given {@link SagaConfiguration} * exists */ default <T extends EventProcessor> Optional<T> sagaEventProcessor(Class<?> sagaType) { return eventProcessorByProcessingGroup(sagaProcessingGroup(sagaType)); }
@Override public void initialize(Configuration config) { this.config = config; eventProcessingConfiguration().registerHandlerInvoker(processorInfo.getProcessingGroup(), c -> sagaManager.get()); eventProcessingConfiguration().registerTokenStore(processorInfo.getProcessingGroup(), c -> tokenStore.get()); eventProcessingConfiguration().configureMessageMonitor(processorInfo.getProcessingGroup(), c -> (MessageMonitor<Message<?>>) messageMonitor.get()); eventProcessingConfiguration().configureErrorHandler(processorInfo.getProcessingGroup(), c -> errorHandler.get()); eventProcessingConfiguration().configureRollbackConfiguration(processorInfo.getProcessingGroup(), c -> rollbackConfiguration.get()); eventProcessingConfiguration().configureTransactionManager(processorInfo.getProcessingGroup(), c -> transactionManager.get()); handlerInterceptors.forEach(i -> eventProcessingConfiguration() .registerHandlerInterceptor(processorInfo.getProcessingGroup(), i)); if (processorInfo.isCreateNewProcessor()) { switch (processorInfo.getType()) { case TRACKING: eventProcessingConfiguration().registerEventProcessor(processorInfo.getProcessingGroup(), this::buildTrackingEventProcessor); break; case SUBSCRIBING: eventProcessingConfiguration().registerEventProcessor(processorInfo.getProcessingGroup(), this::buildSubscribingEventProcessor); break; default: throw new IllegalStateException("Unsupported event processor type."); } } }
/** * Obtains Event Processor by processing group name. This method is to be called after Event Processor Registry is * initialized. * * @param processingGroup The name of the processing group * @param <T> The type of processor expected * @return an Optional referencing the processor */ @SuppressWarnings("unchecked") public <T extends EventProcessor> Optional<T> eventProcessorByProcessingGroup(String processingGroup) { return (Optional<T>) Optional.ofNullable(eventProcessors() .get(processorNameForProcessingGroup(processingGroup))); }
/** * Returns an {@link EventProcessor} by the given {@code processingGroup} if present, matching the given * {@code expectedType}. * * @param processingGroup a {@link String} specifying the processing group of an {@link EventProcessor} * @param expectedType the type of the {@link EventProcessor} to return * @param <T> the type of the expected {@link EventProcessor} * @return an {@link Optional} referencing the {@link EventProcessor}, if present and of expected type */ default <T extends EventProcessor> Optional<T> eventProcessorByProcessingGroup(String processingGroup, Class<T> expectedType) { return eventProcessorByProcessingGroup(processingGroup).filter(expectedType::isInstance) .map(expectedType::cast); }
/** * Register a subscribing event processor with given {@code name} that subscribes to the Event Bus. * * @param name The name of the Event Processor * @return event processing configuration for chaining purposes */ public EventProcessingConfiguration registerSubscribingEventProcessor(String name) { return registerSubscribingEventProcessor(name, Configuration::eventBus); }
@Override public void initialize(Configuration config) { this.configuration = config; eventProcessors.clear(); Map<String, List<Function<Configuration, EventHandlerInvoker>>> builderFunctionsPerProcessor = new HashMap<>(); invokerBuilders.forEach((processingGroup, builderFunctions) -> { String processorName = processorNameForProcessingGroup(processingGroup); builderFunctionsPerProcessor.compute(processorName, (k, currentBuilderFunctions) -> { if (currentBuilderFunctions == null) { return builderFunctions; } currentBuilderFunctions.addAll(builderFunctions); return currentBuilderFunctions; }); }); builderFunctionsPerProcessor.forEach((processorName, builderFunctions) -> eventProcessors.put(processorName, new Component<>(config, processorName, c -> buildEventProcessor(config, builderFunctions, processorName))) ); }
/** * 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 event processing configuration for chaining purposes */ public EventProcessingConfiguration configureMessageMonitor(String name, Function<Configuration, MessageMonitor<Message<?>>> messageMonitorBuilder) { return configureMessageMonitor(name, (configuration, componentType, componentName) -> messageMonitorBuilder .apply(configuration)); }
/** * Configures a {@link org.axonframework.eventhandling.ErrorHandler} for the * {@link org.axonframework.eventhandling.EventProcessor} of the given {@code name}. This * overrides the default ErrorHandler configured through the {@link org.axonframework.config.Configurer}. * * @param name The name of the event processor * @param errorHandlerBuilder The {@link org.axonframework.eventhandling.ErrorHandler} to use for the * {@link org.axonframework.eventhandling.EventProcessor} with the given {@code name} * @return this {@link EventHandlingConfiguration} instance for further configuration * @deprecated use {@link EventProcessingConfiguration#configureErrorHandler(String, Function)} instead */ @Deprecated public EventHandlingConfiguration configureErrorHandler(String name, Function<Configuration, ErrorHandler> errorHandlerBuilder) { errorHandlers.put(name, errorHandlerBuilder); onInit.add(conf -> conf.eventProcessingConfiguration().configureErrorHandler(name, errorHandlerBuilder)); return this; }
@Override public Configuration buildConfiguration() { if (!initialized) { verifyIdentifierFactory(); boolean missingEventProcessingConfiguration = modules.stream() .noneMatch(m -> m.unwrap() instanceof EventProcessingConfiguration); if (missingEventProcessingConfiguration) { registerModule(new EventProcessingConfiguration()); } prepareModules(); invokeInitHandlers(); } return config; }
/** * Returns an {@link EventProcessor} by the given {@code processingGroup} if present, matching the given * {@code expectedType}. * * @param processingGroup a {@link String} specifying the processing group of an {@link EventProcessor} * @param expectedType the type of the {@link EventProcessor} to return * @param <T> the type of the expected {@link EventProcessor} * @return an {@link Optional} referencing the {@link EventProcessor}, if present and of expected type */ default <T extends EventProcessor> Optional<T> eventProcessorByProcessingGroup(String processingGroup, Class<T> expectedType) { return eventProcessorByProcessingGroup(processingGroup).filter(expectedType::isInstance) .map(expectedType::cast); }
@Autowired public void config(EventProcessingConfiguration epConfig, @Qualifier("trade-events") SubscribableMessageSource<EventMessage<?>> tradeEvents) { epConfig.registerSubscribingEventProcessor("trading", c -> tradeEvents); }
/** * Configures the factory 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 messageMonitorFactory The factory to use * @return this EventHandlingConfiguration instance for further configuration * @deprecated use {@link EventProcessingConfiguration#configureMessageMonitor(String, MessageMonitorFactory)} instead */ @Deprecated public EventHandlingConfiguration configureMessageMonitor(String name, MessageMonitorFactory messageMonitorFactory) { messageMonitorFactories.put(name, messageMonitorFactory); onInit.add(conf -> conf.eventProcessingConfiguration().configureMessageMonitor(name, messageMonitorFactory)); return this; }
/** * Configures the default {@link org.axonframework.eventhandling.ErrorHandler} for any * {@link org.axonframework.eventhandling.EventProcessor}. This can be overridden per EventProcessor by calling the * {@link EventHandlingConfiguration#configureErrorHandler(String, Function)} function. * * @param errorHandlerBuilder The {@link org.axonframework.eventhandling.ErrorHandler} to use for the * {@link org.axonframework.eventhandling.EventProcessor} with the given {@code name} * @return this {@link EventHandlingConfiguration} instance for further configuration * @deprecated use {@link EventProcessingConfiguration#configureErrorHandler(Function)} instead */ @Deprecated public EventHandlingConfiguration configureErrorHandler(Function<Configuration, ErrorHandler> errorHandlerBuilder) { defaultErrorHandler.update(errorHandlerBuilder); onInit.add(conf -> conf.eventProcessingConfiguration().configureErrorHandler(errorHandlerBuilder)); return this; }
/** * Returns the {@link EventProcessor} with the given {@code name} if present, matching the given * {@code expectedType}. * * @param name a {@link String} specifying the name of the {@link EventProcessor} to return * @param expectedType the type of the {@link EventProcessor} to return * @param <T> the type of the expected {@link EventProcessor} * @return an {@link Optional} referencing the {@link EventProcessor}, if present and of expected type */ default <T extends EventProcessor> Optional<T> eventProcessor(String name, Class<T> expectedType) { return eventProcessor(name).filter(expectedType::isInstance).map(expectedType::cast); }
@Override public Iterator<EventProcessor> iterator() { return eventProcessingConfiguration.eventProcessors().values().iterator(); } }
/** * Obtains an Saga {@link EventProcessor} implementation for the given {@code sagaType}. * * @param sagaType the type of Saga for which to get the Event Processor * @param <T> the type of the expected {@link EventProcessor} * @return an {@link Optional} specifying whether an {@link EventProcessor} for the given {@link SagaConfiguration} * exists */ default <T extends EventProcessor> Optional<T> sagaEventProcessor(Class<?> sagaType) { return eventProcessorByProcessingGroup(sagaProcessingGroup(sagaType)); }
/** * Returns the Event Processor by the given {@code processingGroup}, if present and of the given {@code * expectedType}. * * @param processingGroup The name of the processing group * @param expectedType The type of processor expected * @param <T> The type of processor expected * @return an Optional referencing the processor, if present and of expected type */ public <T extends EventProcessor> Optional<T> eventProcessorByProcessingGroup(String processingGroup, Class<T> expectedType) { return eventProcessorByProcessingGroup(processingGroup).filter(expectedType::isInstance) .map(expectedType::cast); }
/** * Register a subscribing processor with given {@code name} that subscribes to the given {@code messageSource}. * This allows the use of standard Subscribing Processors that listen to another source than the Event Bus. * * @param name The name of the Event Processor * @param messageSource The source the processor should read from * @return this EventHandlingConfiguration instance for further configuration * @deprecated use {@link EventProcessingConfiguration#registerSubscribingEventProcessor(String, Function)} instead */ @SuppressWarnings("UnusedReturnValue") @Deprecated public EventHandlingConfiguration registerSubscribingEventProcessor( String name, Function<Configuration, SubscribableMessageSource<? extends EventMessage<?>>> messageSource) { onInit.add(conf -> conf.eventProcessingConfiguration() .registerSubscribingEventProcessor(name, messageSource)); return this; }