-
Notifications
You must be signed in to change notification settings - Fork 413
Open
Labels
Description
ZookeeperAutoServiceRegistration throws an exception when ServiceInstanceRegistration method getServiceInstance() is called before ZookeeperAutoServiceRegistration method getPort()
It happens because method getServiceInstance() calls build() and when getPort() will be called it will return null instead 0.
Lines 64 to 69 in ec845a4
| public ServiceInstance<ZookeeperInstance> getServiceInstance() { | |
| if (this.serviceInstance == null) { | |
| build(); | |
| } | |
| return this.serviceInstance; | |
| } |
Lines 71 to 73 in ec845a4
| protected void build() { | |
| this.serviceInstance = this.builder.build(); | |
| } |
Lines 83 to 88 in ec845a4
| public int getPort() { | |
| if (this.serviceInstance == null) { | |
| return 0; | |
| } | |
| return this.serviceInstance.getPort(); | |
| } |
Lines 70 to 79 in ec845a4
| protected void register() { | |
| if (!this.properties.isRegister()) { | |
| log.debug("Registration disabled."); | |
| return; | |
| } | |
| if (this.registration.getPort() == 0) { | |
| this.registration.setPort(getPort().get()); | |
| } | |
| super.register(); | |
| } |
Also getInstanceId() method returns null.
Use case when we need to call getServiceInstance for example to create leader candidate and associate with registration id for further understanding which node is a leader.
@Bean
public DefaultCandidate bean(ServiceInstanceRegistration registration) {
return return new DefaultCandidate(registration.getServiceInstance().getId(), "default");
}