public void advertise(Registration registration) { if (this.advertisements.contains(registration)) { return; } AgentClient client = this.agentClientInjector.getValue(); com.orbitz.consul.model.agent.Registration consulReg = ImmutableRegistration.builder() .address(registration.getAddress()) .port(registration.getPort()) .id(serviceId(registration)) .name(registration.getName()) .addTags(registration.getTags().toArray(new String[]{})) .check(com.orbitz.consul.model.agent.Registration.RegCheck.ttl(3L)) .build(); client.register(consulReg); this.advertisements.add(registration); }
.address(getMicroservice().getHostname()) .port(getMicroservice().getInstanceSettings().getGrpcPort()) .check(Registration.RegCheck.ttl(30L)).tags(tags).meta(Collections.singletonMap("version", getMicroservice().getVersion().getVersionIdentifier())) .build();
/** * Registers the client as a service with Consul with a ttl check. * * @param port The public facing port of the service to register with Consul. * @param ttl Time to live in seconds for the Consul dead man's switch. * @param name Service name to register. * @param id Service id to register. * @param tags Tags to register with. * @param meta Meta to register with. */ public void register(int port, long ttl, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.ttl(ttl); register(port, check, name, id, tags, meta); }