Reputation: 31
I'm trying to define my "Event Handler Interceptor", I followed the instruction on the official documentation here, but I get the following error:
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:
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!
Upvotes: 2
Views: 859
Reputation: 7275
Luckily, the problem is rather straightforward (and does not correlate to Axon directly).
The problem is you should've used @Autowired
instead of @Bean
on the configureEventProcessing(Configurer)
method.
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.
Final note of fine tuning, you can use the EventProcessingConfigurer
as a parameter instead of the Configurer#eventProcessing
call. 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.
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
.
A quick and easy way to specify a processing group for an Event Handling Component is by adding the @ProcessingGroup
annotation on class level.
Upvotes: 3