public class MyCommandHandler implements MessageDispatchInterceptor
@Override
public BiFunction
//... your interceptor logic here
return command;
};
} }
@Configuration public class MyAxonConfig {
@Autowired public void configureEventHandling(EventProcessingConfigurer configurer) { configurer.registerDispatchInterceptor(new MyCommandHandler()); }
//... Other Axon configuration }
@Repository
public interface MyRepository extends ReactiveCrudRepository
@Override
Mono save(S entity);
// Here we add the interceptor to the save method
@Override
default Mono save(S entity) {
return Mono.defer(() -> Mono.just(entity))
.flatMap(e -> {
// First, we create and attach the interceptor
MessageDispatchInterceptor
// Then we dispatch the message and execute the interceptor
return Mono.fromFuture(getMessageSource().dispatch(message, callback));
});
} }
以这种方式,您现在可以使用Axon框架拦截处理程序和存储库的命令和事件,并