@Override public void advertise(String name, SocketBinding binding, String...tags) { Registration registration = new Registration("consul", name, binding.getAddress().getHostAddress(), binding.getAbsolutePort(), tags ); this.advertiser.advertise(registration); }
public synchronized void advertise(String name, SocketBinding binding, String... tags) { Registration registration = new Registration(sourceKey(this.node), name, binding.getAddress().getHostAddress(), binding.getAbsolutePort(), tags); this.registrations.put(name + ":" + binding.getName(), registration); advertise(registration); }
public synchronized void advertise(String name, SocketBinding binding, String... tags) throws Exception { Registration registration = new Registration(sourceKey(this.node), name, binding.getAddress().getHostAddress(), binding.getAbsolutePort(), tags); this.registrations.put(name + ":" + binding.getName(), registration); advertise(registration); }
@Override public void notify(Map<HostAndPort, ServiceHealth> newValues) { Set<Registration> previousEntries = topologyManager.registrationsForService(this.name); Set<Registration> newEntries = newValues.values().stream() .map(e -> new Registration("consul", this.name, e.getService().getAddress(), e.getService().getPort()) .addTags(e.getService().getTags()) ) .collect(Collectors.toSet()); previousEntries.stream() .filter(e -> !newEntries.contains(e)) .forEach(e -> { this.topologyManager.unregister(e); }); newEntries.stream() .filter(e -> !previousEntries.contains(e)) .forEach(e -> { this.topologyManager.register(e); }); } }
private Set<Registration> registrationsForService(IService service) { Set<Registration> newEntries = new HashSet<>(); // Only expose the service's default port and anything running on the https port service.getPorts() .stream() .filter(servicePort -> servicePort.getPort() == service.getPort() || servicePort.getPort() == DEFAULT_HTTPS_PORT) .forEach(servicePort -> { Registration registration = new Registration(TOPOLOGY_SOURCE_KEY, service.getName(), service.getName(), servicePort.getPort()); if (servicePort.getPort() == DEFAULT_HTTPS_PORT) { registration.addTags(Collections.singletonList("https")); } else if (servicePort.getPort() == service.getPort()) { registration.addTags(Collections.singletonList("http")); } newEntries.add(registration); }); return newEntries; }