0

I have two different spring-cloud services using spring-cloud-starter-bus-kafka to receive new config refresh from a centralize service. When call refreshBusEndpoint.busRefresh() in centralize

  • service-A receive:RemoteApplicationEvent
originService = null
destinationService = "**"
id = "6a8d95fc-5954-4eac-b45d-ba8b34da1f9f"
timestamp = 1590192298082
  • service-B received:
originService = "centralize-configuration:8888:3f31c745f983d0dd22d9988758d518a0"
destinationService = "**"
id = "7e986811-1c12-4d85-939c-054c5de9171f"
timestamp = 1590221239086

The problem is originService = null will cause error

-> BusAutoConfiguration acceptRemote(RemoteApplicationEvent event)
-> !this.serviceMatcher.isFromSelf(event)
-> matcher.match(originService, serviceId)
-> AntPathMatcher.class
-> match(), doMatch() 

statement stop by null pointer: pattern.startsWith(this.pathSeparator)

  • Both services using:
    spring-cloud.version -> Greenwich.RELEASE 
    spring.boot.version -> 2.1.6.RELEASE 
    spring.kafka.version -> 2.2.9.RELEASE 

Can someone explain the reason for my service got event with originService = null ?

1 Answers1

-2

Solution example:

@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!";
    }
}

So the idea is to provide serviceId manually.

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

  • 1
    Thank you! I found the reason though, it's config spring.jackson.property-naming-strategy = SNAKE_CASE which caused originService null (become origin_service) – chi nguyen May 25 '20 at 09:24