我有两个不同的spring-cloud服务,使用spring-cloud-starter-bus-kafka来接收来自centralize服务的新配置刷新。当在centralize中调用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()
语句以空指针停止:pattern.artsWith(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。
源头:/githubhttps:/github.comspring-cloudspring-cloud-busissues133#issuecomment-467755362。https:/programmer.inkthpring-cloud-bus-custom-event-stepping.html。