public void listenInstanceRegisteredEvent()

in alpha/alpha-spring-cloud-starter-consul/src/main/java/org/apache/servicecomb/pack/alpha/server/discovery/consul/AlphaConsulAutoConfiguration.java [105:130]


  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,
            QueryParams.Builder.builder().build());
        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);
          });
        }
      }
    }
  }