env.onStarted(() -> agentClient.register(registration)); env.onStop(() -> agentClient.deregister(registration.getId()));
public void register(Registration registration) { register(registration, QueryOptions.BLANK); }
/** * 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); }
/** * Registers the client as a service with Consul with a script based check. * * @param port The public facing port of the service to register with Consul. * @param args Specifies command argument to run to update the status of the check.. * @param interval Health script run interval in seconds. * @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, List<String> args, long interval, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.args(args, interval); register(port, check, name, id, tags, meta); }
/** * Registers the client as a service with Consul with an http based check * * @param port The public facing port of the service to register with Consul. * @param http Health check URL. * @param interval Health script run interval in seconds. * @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, URL http, long interval, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.http(http.toExternalForm(), interval); register(port, check, name, id, tags, meta); }
/** * Registers the client as a service with Consul with a script based check. * * @param port The public facing port of the service to register with Consul. * @param args Specifies command argument to run to update the status of the check.. * @param interval Health script run interval in seconds. * @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, String args, long interval, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.args(Collections.singletonList(args), interval); register(port, check, name, id, tags, meta); }
/** * Registers the client as a service with Consul with a TCP based check * * @param port The public facing port of the service to register with Consul. * @param tcp Health check TCP host and port. * @param interval Health script run interval in seconds. * @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, HostAndPort tcp, long interval, String name, String id, List<String> tags, Map<String, String> meta) { Registration.RegCheck check = Registration.RegCheck.tcp(tcp.toString(), interval); register(port, check, name, id, tags, meta); }
@Test public void doHealthCheck() throws Exception { Consul consul = Consul.builder().withHostAndPort(HostAndPort.fromParts("127.0.0.1", 8500)).build(); AgentClient agentClient = consul.agentClient(); String serviceName = "health-check-service"; String serviceTag = "test"; agentClient.register(9090, HostAndPort.fromParts("127.0.0.1", 8080), 3l, serviceName, "service-id", serviceTag); TimeUnit.MINUTES.sleep(2); } }
@Test public void registerServiceForConsul() throws Exception { Consul consul = Consul.builder().withHostAndPort(HostAndPort.fromParts("127.0.0.1", 8500)).build(); AgentClient agentClient = consul.agentClient(); String serviceId = UUID.randomUUID().toString(); String serviceName = "java-consul-service"; String serviceTag = "test"; long ttl = 3l; agentClient.register(9090, ttl, serviceName, serviceId, serviceTag); agentClient.pass(serviceId); System.out.println("succ."); TimeUnit.MINUTES.sleep(2); } }
try { if (!getConsulClient().agentClient().isRegistered(serviceId)){ getConsulClient().agentClient().register( webconsolePort, regCheck,
public SessionTask(Consul consul, String serviceName, String serviceId, Consumer<Throwable> fatalErrorConsumer) { serviceId = defaultIfNull(serviceId, serviceName); this.serviceId = serviceId; this.serviceName = requireNonNull(serviceName); this.consul = requireNonNull(consul); this.fatalErrorConsumer = requireNonNull(fatalErrorConsumer); try { final List<String> tags = singletonList("couchbase-elasticsearch-connector");// emptyList(); final Map<String, String> meta = singletonMap("uuid", serviceUuid); // todo catch exception, retry with backoff (wait for consul agent to start) final int sessionTtlSeconds = HEALTH_CHECK_INTERVAL_SECONDS * 2; consul.agentClient().register(0, sessionTtlSeconds, this.serviceName, this.serviceId, tags, meta); passHealthCheck(); this.sessionId = consul.sessionClient().createSession(ImmutableSession.builder() .name("couchbase:cbes:" + this.serviceId) .behavior("delete") .lockDelay("15s") .addChecks("service:" + this.serviceId) // consul client library names the health check "service:<serviceId>" .build() ).getId(); } catch (Throwable t) { fatalErrorConsumer.accept(t); // todo need to send to fatalErrorConsumer? throw t; } }
public void register(String name, int port) { log.info("Will register " + name + " with port " + port); AgentClient agentClient = client.agentClient(); Registration service = ImmutableRegistration.builder().id(name).name(name).port(port) .check(Registration.RegCheck.http("http://localhost:" + port + Constants.HEALTH_CONTEXT, 60, 5)).build(); agentClient.register(service); }
this.consulAgentClient.register(builder.build(), ConsulUtility.getAclToken(this.consulAclToken));
this.consulAgentClient.register(builder.build(), ConsulUtility.getAclToken(this.consulAclToken));
final Map<String, String> meta = singletonMap("uuid", serviceUuid); consul.agentClient().register(0, 30L, this.serviceName, this.serviceId, tags, meta);
client.agentClient().register(registration);
/** * Registers the client as a service with Consul with an existing {@link com.orbitz.consul.model.agent.Registration.RegCheck} * * @param port The public facing port of the service to register with Consul. * @param check The health check to run periodically. Can be null. * @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, Registration.RegCheck check, String name, String id, List<String> tags, Map<String, String> meta) { Registration registration = ImmutableRegistration .builder() .port(port) .check(Optional.ofNullable(check)) .name(name) .id(id) .tags(tags) .meta(meta) .build(); register(registration); }
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); }
/** * Registers the client as a service with Consul with multiple checks * * @param port The public facing port of the service to register with Consul. * @param checks The health checks to run periodically. * @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, List<Registration.RegCheck> checks, String name, String id, List<String> tags, Map<String, String> meta) { Registration registration = ImmutableRegistration .builder() .port(port) .checks(checks) .name(name) .id(id) .tags(tags) .meta(meta) .build(); register(registration); }
getMicroservice().getVersion().getVersionIdentifier())) .build(); agentClient.register(service);