如何使用 Spring 在 Axon 中配置事件处理器?

How do I configure Event Processors in Axon with Spring?

显然 Axon 默认使用 TrackingEventProcessors。我想改用 SubscribingEventProcessorsdocs say that the latter is already the default,但它们似乎已经过时了。

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.

比如建议这样配置:

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

但是,v4 中没有 EventHandlingConfiguration(v3 中有)。

我需要使用 SubscribingEventProcessors 在与命令处理相同的事务中执行读取模型更新。这在 4.0 中如何配置?

事件处理器的这方面可以在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

最好的, 伊万