首页 > 解决方案 > How do I configure Event Processors in Axon with Spring?

问题描述

Apparently Axon uses TrackingEventProcessors by default. I would like to use SubscribingEventProcessors instead. The docs say that the latter is already the default, but they seem to be outdated.

By default, Axon will use Subscribing Event Processors. It is possible to change how Handlers are assigned and how processors are configured using the EventHandlingConfiguration class of the Configuration API.

For instance, it is suggested to perform configurations like so:

@Autowired
public void configure(EventHandlingConfiguration config) {
    config.usingTrackingProcessors(); // default all processors to tracking mode.
}

However, there is no EventHandlingConfiguration in v4 (there was in v3).

I need to use the SubscribingEventProcessors to perform read-model updates in the same transaction as command handling. How can this be configured in 4.0?

标签: event-handlingaxon

解决方案


事件处理器的这方面可以配置为application.yml/application.properties

axon:
  eventhandling:
    processors:
      NAME_OF_THE_PROCESSOR:
        mode: subscribing

我想你是对的。文档引用了旧 API。

您可以将所有事件处理器构建器配置为使用 SubscribingEventProcessor

 @Autowired
 public void configure(EventProcessingConfigurer configurer) {
      configurer.usingSubscribingEventProcessors(); 
 }

https://github.com/AxonFramework/AxonFramework/blob/axon-4.0/config/src/main/java/org/axonframework/config/EventProcessingConfigurer.java#L216

最好的,伊万


推荐阅读