首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >春云总线kafka RemoteApplicationEvent originService刷新时为空。

春云总线kafka RemoteApplicationEvent originService刷新时为空。
EN

Stack Overflow用户
提问于 2020-05-23 09:43:32
回答 1查看 442关注 0票数 0

我有两种不同的spring云服务,使用从集中式服务中接收新的配置刷新。集中调用refreshBusEndpoint.busRefresh()时

receive:RemoteApplicationEvent

  • 服务

代码语言:javascript
复制
originService = null
destinationService = "**"
id = "6a8d95fc-5954-4eac-b45d-ba8b34da1f9f"
timestamp = 1590192298082

  • 服务-B接收:

代码语言:javascript
复制
originService = "centralize-configuration:8888:3f31c745f983d0dd22d9988758d518a0"
destinationService = "**"
id = "7e986811-1c12-4d85-939c-054c5de9171f"
timestamp = 1590221239086

问题是originService = null将导致错误

代码语言:javascript
复制
-> BusAutoConfiguration acceptRemote(RemoteApplicationEvent event)
-> !this.serviceMatcher.isFromSelf(event)
-> matcher.match(originService, serviceId)
-> AntPathMatcher.class
-> match(), doMatch() 

语句停止空指针: pattern.startsWith(this.pathSeparator)

两个服务都使用:

代码语言:javascript
复制
    spring-cloud.version -> Greenwich.RELEASE 
    spring.boot.version -> 2.1.6.RELEASE 
    spring.kafka.version -> 2.2.9.RELEASE 

有人能用originService = null解释我的服务got事件的原因吗?

EN

回答 1

Stack Overflow用户

发布于 2020-05-24 08:34:54

解决方案示例:

代码语言:javascript
复制
@RequestMapping("/hello")
@RestController
public class HelloController {

    @Autowired
    private ApplicationContext applicationContext;
    @Autowired
    private BusProperties busProperties;

    @GetMapping("/test")
    public String test(@RequestParam("message") String message) {
        String id = busProperties.getId();
        applicationContext.publishEvent(new CustomApplicationEvent(this, id, null, message));
    return "Sending succeeded!";
    }
}

因此,我们的想法是手动提供serviceId。

资料来源:https://github.com/spring-cloud/spring-cloud-bus/issues/133#issuecomment-467755362 https://programmer.ink/think/spring-cloud-bus-custom-event-stepping.html

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61970145

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档