HI,
I have a requirement to implement an audit of events that occurred in our system to a separate system that aggregates auditing of several systems. The approach that I want to take is to implement a MessageHandlerInterceptor that does the necessary work after the commit of the event to the event store. For brevity I omitted the part where it does the call and used a simple log statement.
`
@Slf4j
public class AuditInterceptor<T extends Message<?>> implements MessageHandlerInterceptor {
@Override
public Object handle(final UnitOfWork<? extends T> unitOfWork, final InterceptorChain interceptorChain) throws Exception {
unitOfWork.afterCommit(unit -> {
final T message = unit.getMessage();
log.info("{}",message);
});
return interceptorChain.proceed();
}
}
`
I want to take this approach since I don’t want to have to register Event Handlers for every event in the system to do the auditing. The issue that I am facing currently is registering the above interceptor with the appropriate EventProcessor. In our project we are not registering an EventProcesor explicitly, but instead rely on the default configured event processor which is pulled in by Spring Boot Autoconfigure. However I am unsure on how to get access to this. The documentation for Axon 3.1 gives this example :
`
public class EventProcessorConfiguration {
public EventProcessingConfiguration eventProcessingConfiguration() {
return new EventProcessingConfiguration()
.registerTrackingEventProcessor("my-tracking-processor")
.registerHandlerInterceptor("my-tracking-processor", configuration -> new MyEventHandlerInterceptor());
}
}
`
However I am unable to find the EventProcessorConfiguration in the classpath in order to register the Handler Interceptor. A likely candidate for this seems to be TrackingEventProcessorConfiguration but this seems to be an internal class of the Axon framework.
So my questions are :
-
How do I register the above interceptor with the Event Processor such that it is invoked after an Event is committed ot the Event store?
-
Am I on the right track with this approach or is there another way that I am not considering?
-
If this can be configured in this way. my hope is that it will only execute the first time that an event is applied on an aggregate. Will this be the case, or will the interceptor be invoked when events are replayed?