Axonframework如何在响应式存储库中使用MessageDispatchInterceptor?
创始人
2024-09-29 08:00:16
0
  1. 首先,在您的命令处理程序或事件处理程序类上实现MessageDispatchInterceptor接口,例如:

public class MyCommandHandler implements MessageDispatchInterceptor> { //... Command handling methods

@Override public BiFunction, CommandMessage> handle(List> messages) { return (index, command) -> {

       //... your interceptor logic here

       return command;
   };

} }

  1. 然后,在您的配置文件中注册该拦截器,例如:

@Configuration public class MyAxonConfig {

@Autowired public void configureEventHandling(EventProcessingConfigurer configurer) { configurer.registerDispatchInterceptor(new MyCommandHandler()); }

//... Other Axon configuration }

  1. 最后,在您的响应式存储库中使用拦截器,例如:

@Repository public interface MyRepository extends ReactiveCrudRepository { //... Crud repository methods

@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> interceptor = (messages) -> { return (index, message) -> { //... your interceptor logic here return message; }; }; Object[] args = {this.getClass().getName(), "save", Collections.singletonList(entity)}; InterceptorChain processor = new DefaultInterceptorChain(interceptor, this, args, this::save); CommandCallback callback = new DefaultCallback<>(processor); Message message = new GenericCommandMessage<>(entity);

               // Then we dispatch the message and execute the interceptor
               return Mono.fromFuture(getMessageSource().dispatch(message, callback));
           });

} }

以这种方式,您现在可以使用Axon框架拦截处理程序和存储库的命令和事件,并

相关内容

热门资讯

透视线上!聚星ai辅助工具收费... 透视线上!聚星ai辅助工具收费多少(透视)一贯是真的有挂(详细辅助AI教程)1、ai辅助优化,发牌逻...
盘点一款!steampoker... 盘点一款!steampokermaster辅助,cloudpoker外挂,规律教程(有挂辅助);建议...
透视攻略!wepoker辅助透... 透视攻略!wepoker辅助透视软件(透视)本来真的是有挂(详细辅助AI教程)1、每一步都需要思考,...
指导大家!wepoker辅助透... 指导大家!wepoker辅助透视软件,德州局透视脚本免费版下载手机版,技巧教程(有挂教程);亲真的是...
透视讲解!wepoker私人局... 透视讲解!wepoker私人局俱乐部(透视)确实是真的有挂(详细辅助总结教程)1、任何ai辅助神器的...
技术分享!cloudpoker... 技术分享!cloudpoker怎么开挂,wpk免费辅助,线上教程(有挂技巧);原来确实真的有挂(需添...
透视肯定!拱趴大菠萝作弊方法(... 透视肯定!拱趴大菠萝作弊方法(透视)好像有挂(详细辅助wpk教程)在进入辅助挂后,参与本局比赛的八名...
盘点一款!哈糖大菠萝怎么挂,w... 盘点一款!哈糖大菠萝怎么挂,wepoker亲友圈有用吗,揭秘教程(有挂辅助)1、许多玩家不知道wep...
透视总结!aapoker辅助器... 透视总结!aapoker辅助器怎么用(透视)好像真的是有挂(详细辅助攻略教程)1)aapoker辅助...
记者发布!xpoker辅助怎么... 记者发布!xpoker辅助怎么用,wepoker透视苹果系统,安装教程(有挂方法);1.wepoke...