[英]Axon - Event Handler Interceptor configuration
I'm trying to define my "Event Handler Interceptor", I followed the instruction on the official documentation here , but I get the following error:我正在尝试定义我的“事件处理程序拦截器”,我按照官方文档here的说明进行操作,但出现以下错误:
org.springframework.beans.factory.BeanCreationException: error when creating the bean with name 'configureEventProcessing' defined in the resource path class [com / prog / boot / config / EventProcessorConfiguration.class]: invalid factory method 'configureEventProcessing': must have an empty non-return type!
My current configuration call:我当前的配置调用:
@Configuration
public class EventProcessorConfiguration {
@Bean
public void configureEventProcessing(Configurer configurer) {
configurer.eventProcessing()
.registerTrackingEventProcessor("my-tracking-processor")
.registerHandlerInterceptor("my-tracking-processor",
configuration -> new MyEventHandlerInterceptor());
}
}
My event MessageHandlerInterceptor
implementation:我的事件
MessageHandlerInterceptor
实现:
public class MyEventHandlerInterceptor implements MessageHandlerInterceptor<EventMessage<?>> {
@Override
public Object handle(UnitOfWork<? extends EventMessage<?>> unitOfWork, InterceptorChain interceptorChain)
throws Exception {
EventMessage<?> event = unitOfWork.getMessage();
String userId = Optional.ofNullable(event.getMetaData().get("userId")).map(uId -> (String) uId)
.orElseThrow(Exception::new);
if ("axonUser".equals(userId)) {
return interceptorChain.proceed();
}
return null;
}
}
What am I doing wrong?我究竟做错了什么?
Thanks!谢谢!
Luckily, the problem is rather straightforward (and does not correlate to Axon directly).幸运的是,这个问题相当简单(并且与 Axon 没有直接关系)。
The problem is you should've used @Autowired
instead of @Bean
on the configureEventProcessing(Configurer)
method.问题是您应该在
configureEventProcessing(Configurer)
方法上使用@Autowired
而不是@Bean
。 The @Bean
annotation on a method will make it a "Bean creation method", whilst you only want to tie into the auto configuration to "further configure" the Event Processors.方法上的
@Bean
注释将使其成为“Bean 创建方法”,而您只想绑定到自动配置以“进一步配置”事件处理器。
Final note of fine tuning, you can use the EventProcessingConfigurer
as a parameter instead of the Configurer#eventProcessing
call.微调的最后说明,您可以使用
EventProcessingConfigurer
作为参数而不是Configurer#eventProcessing
调用。 That shortens your code just a little.这会稍微缩短您的代码。
Update更新
The provided configuration would, given the auto-wiring adjustment work as expected.提供的配置将按预期进行自动接线调整工作。 Granted, it does expect an Event Handling Component to be present which is part of the
""my-tracking-processor"
processing group.当然,它确实希望出现一个事件处理组件,它是
""my-tracking-processor"
处理组的一部分。
If there are no Event Handling components present in that processing group, no events will be passed to it and thus none will be pushed through the MessageHandlerInterceptor
.如果该处理组中不存在事件处理组件,则不会将任何事件传递给它,因此不会通过
MessageHandlerInterceptor
推送任何事件。
A quick and easy way to specify a processing group for an Event Handling Component is by adding the @ProcessingGroup
annotation on class level.为事件处理组件指定处理组的一种快速简便的方法是在类级别添加
@ProcessingGroup
注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.