Spring boot @EventHandler重试逻辑和DistributedCommandBus设置
第一个问题: 因此,我通过以下方式使用Spring Eureka和DistributedCommandBus集:Spring boot @EventHandler重试逻辑和DistributedCommandBus设置,spring-boot,axon,Spring Boot,Axon,第一个问题: 因此,我通过以下方式使用Spring Eureka和DistributedCommandBus集: public CommandRouter springCloudCommandRouter(DiscoveryClient discoveryClient, Registration localServiceInstance) { ... } public CommandBusConnector springHttpCommandBusConnector(@Qualifier
public CommandRouter springCloudCommandRouter(DiscoveryClient discoveryClient, Registration localServiceInstance) { ... }
public CommandBusConnector springHttpCommandBusConnector(@Qualifier("localSegment") CommandBus localSegment, RestOperations restOperations, Serializer serializer) { .. }
public DistributedCommandBus springCloudDistributedCommandBus(CommandRouter commandRouter, CommandBusConnector commandBusConnector) { ... }
对于这一部分我的问题是,我如何证明这是有效的?我有两个K8播客运行上述代码,其中一个运行@CommandHandler
,另一个运行@EventSourcingEvent
,但在日志中没有看到任何指示它正在使用总线的内容
我只是想证明它是“有效的”,因为我已经被要求这样做
Eureka部件正在工作,我看到了上述仪表板上的所有信息
编辑-删除在另一个帖子中提出的第二个问题为了集中精力回答我的答案,我只为你的第一个问题提供一个建议,总结如下: 如何指出我用Eureka设置的
DistributedCommandBus
实际上是将命令路由到不同的实例
我建议围绕这个设置一些日志记录。
这样,您就可以记录消息何时从节点1发送以及何时由节点2处理。
最理想的方法是将日志拦截器
注册为MessageHandlerInterceptor
和MessageDispatchInterceptor
为此,您必须在DistributedCommandBus
上注册,但也必须在“本地段”CommandBus
上注册。DistributedCommandBus
将负责调度它,从而在调度时调用LoggingInterceptor
。本地段/CommandBus
负责将命令提供给正确JVM中的命令处理程序,因此在处理时将调用LoggingInterceptor
唯一的缺点是,LoggingInterceptor
将作为脱离Axon框架4.2版的处理程序和分派拦截器。
因此,现在,您只需要将其作为处理程序拦截器
但是,这也就足够了,因为LoggingInterceptor
只会在处理命令时登录。
这将只发生在实际处理命令的节点上
希望这有帮助 我认为你应该把它分成两个不同的问题。从StackOverflow的角度来看,这对经历相同问题的人更有帮助。它使问题和答案更加简洁明了。我可以做到这一点,因为我可能已经通过尝试和错误解决了问题的第二部分。好东西,谢谢edit@sherring。这确实有帮助,我能够看到Spring Eureka后面运行的各种JVM上的日志。有一件事我确实注意到了(可能我在文档中没有注意到),我必须使用以下命令才能使Eureka部件正常工作:``@Bean(name=“localSegment”)public CommandBus configureCommandBus()“``否则spring在无法找到localSegment时失败beanI将假定在自动配置环境中,您不必强制指定
localSegment
。所以,你不得不这么做似乎有点有趣。如果您愿意,您可以将其作为问题提交到框架的存储库中,并提供一个显示失败原因的示例项目。这可能会给你一个很好的机会去弄清楚到底是什么。