[英]spring-cloud bus kafka RemoteApplicationEvent originService is null when refresh
我有两个不同的 spring-cloud 服务,它们使用 spring-cloud-starter-bus-kafka 从集中式服务接收新的配置刷新。 在集中调用 refreshBusEndpoint.busRefresh() 时
originService = null
destinationService = "**"
id = "6a8d95fc-5954-4eac-b45d-ba8b34da1f9f"
timestamp = 1590192298082
originService = "centralize-configuration:8888:3f31c745f983d0dd22d9988758d518a0"
destinationService = "**"
id = "7e986811-1c12-4d85-939c-054c5de9171f"
timestamp = 1590221239086
问题是 originService = null 会导致错误
-> BusAutoConfiguration acceptRemote(RemoteApplicationEvent event)
-> !this.serviceMatcher.isFromSelf(event)
-> matcher.match(originService, serviceId)
-> AntPathMatcher.class
-> match(), doMatch()
语句由 null 指针停止:pattern.startsWith(this.pathSeparator)
spring-cloud.version -> Greenwich.RELEASE
spring.boot.version -> 2.1.6.RELEASE
spring.kafka.version -> 2.2.9.RELEASE
有人可以用 originService = null 解释我的服务发生事件的原因吗?
解决方案示例:
@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 。
Source: https://github.com/spring-cloud/spring-cloud-bus/issues/133#issuecomment-467755362 https://programmer.ink/think/spring-cloud-bus-custom-event-stepping.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.