You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/04/21 03:44:57 UTC
[GitHub] [servicecomb-pack] fengbaicanhe commented on issue #454: fix when
server.port=0, health check fail and also fix lose consul metadata,
such as 'secure=false'
fengbaicanhe commented on issue #454: fix when server.port=0, health check fail and also fix lose consul metadata, such as 'secure=false'
URL: https://github.com/apache/servicecomb-pack/pull/454#issuecomment-485222249
@WillemJiang @coolbeevip
after my explain, i think this solution will be better
```java
@EventListener
public void listenInstanceRegisteredEvent(InstanceRegisteredEvent instanceRegisteredEvent){
if(alphaServerPort == 0){
if(instanceRegisteredEvent.getConfig() instanceof ConsulDiscoveryProperties){
ConsulDiscoveryProperties properties = (ConsulDiscoveryProperties)instanceRegisteredEvent.getConfig();
this.consuleInstanceId = formatConsulInstanceId(properties.getInstanceId());
Response<List<CatalogService>> services = consulClient.getCatalogService(serviceName,null);
if(services.getValue() != null){
services.getValue().stream().filter(service ->
service.getServiceId().equalsIgnoreCase(this.consuleInstanceId)).forEach(service -> {
NewService newservice = new NewService();
newservice.setName(service.getServiceName());
newservice.setId(service.getServiceId());
newservice.setAddress(service.getAddress());
newservice.setPort(service.getServicePort());
List<String> tags = service.getServiceTags();
tags.remove("alpha-server-port=0");
tags.add("alpha-server-port="+actualAlphaServerPort);
newservice.setTags(tags);
consulClient.agentServiceRegister(newservice);
});
}
}
}
}
```
it's only two lines more than @coolbeevip suggestion
```java
newservice.setAddress(service.getAddress());
newservice.setPort(service.getServicePort());
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services