use of com.orbitz.consul.AgentClient in project jim-framework by jiangmin168168.
the class ConsulRegistryService method register.
@Override
public void register(RpcURL url) {
Consul consul = this.buildConsul(url.getRegistryHost(), url.getRegistryPort());
AgentClient agent = consul.agentClient();
ImmutableRegCheck check = ImmutableRegCheck.builder().tcp(url.getHost() + ":" + url.getPort()).interval(CONSUL_HEALTH_INTERVAL).build();
ImmutableRegistration.Builder builder = ImmutableRegistration.builder();
builder.id(CONSUL_ID).name(CONSUL_NAME).addTags(CONSUL_TAGS).address(url.getHost()).port(url.getPort()).addChecks(check);
agent.register(builder.build());
}
use of com.orbitz.consul.AgentClient in project wildfly-swarm by wildfly-swarm.
the class AgentActivator method activate.
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
ServiceTarget target = context.getServiceTarget();
ConsulService consul = new ConsulService(this.fraction.url());
target.addService(ConsulService.SERVICE_NAME, consul).install();
HealthClientService healthClient = new HealthClientService();
target.addService(HealthClientService.SERIVCE_NAME, healthClient).addDependency(ConsulService.SERVICE_NAME, Consul.class, healthClient.getConsulInjector()).install();
CatalogClientService catalogClient = new CatalogClientService();
target.addService(CatalogClientService.SERVICE_NAME, catalogClient).addDependency(ConsulService.SERVICE_NAME, Consul.class, catalogClient.getConsulInjector()).install();
AgentClientService agentClient = new AgentClientService();
target.addService(AgentClientService.SERVICE_NAME, agentClient).addDependency(ConsulService.SERVICE_NAME, Consul.class, agentClient.getConsulInjector()).install();
Advertiser advertiser = new Advertiser();
target.addService(Advertiser.SERVICE_NAME, advertiser).addDependency(AgentClientService.SERVICE_NAME, AgentClient.class, advertiser.getAgentClientInjector()).install();
}
use of com.orbitz.consul.AgentClient in project wildfly-camel by wildfly-extras.
the class ConsulIntegrationTest method testServiceDiscovery.
@Test
public void testServiceDiscovery() throws Exception {
final AgentClient client = getConsul().agentClient();
try {
registrations = new ArrayList<>(3);
for (int i = 0; i < 3; i++) {
Registration r = ImmutableRegistration.builder().id("service-" + i).name("my-service").address("127.0.0.1").addTags("a-tag").addTags("key1=value1").addTags("key2=value2").port(9000 + i).build();
client.register(r);
registrations.add(r);
}
ConsulConfiguration configuration = new ConsulConfiguration();
configuration.setUrl(consulUrl);
ServiceDiscovery discovery = new ConsulServiceDiscovery(configuration);
List<ServiceDefinition> services = discovery.getServices("my-service");
assertNotNull(services);
assertEquals(3, services.size());
for (ServiceDefinition service : services) {
assertFalse(service.getMetadata().isEmpty());
assertTrue(service.getMetadata().containsKey("service_name"));
assertTrue(service.getMetadata().containsKey("service_id"));
assertTrue(service.getMetadata().containsKey("a-tag"));
assertTrue(service.getMetadata().containsKey("key1"));
assertTrue(service.getMetadata().containsKey("key2"));
}
} finally {
if (registrations != null && client != null) {
registrations.forEach(r -> client.deregister(r.getId()));
}
}
}
use of com.orbitz.consul.AgentClient in project wildfly-swarm by wildfly-swarm.
the class Advertiser method advertise.
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);
log.info("Registered service " + consulReg.getId());
}
use of com.orbitz.consul.AgentClient in project wildfly-swarm by wildfly-swarm.
the class Advertiser method unadvertise.
public void unadvertise(String name, String address, int port) {
AgentClient client = this.agentClientInjector.getValue();
Registration r = new Registration("consul", name, address, port, "");
this.advertisements.stream().filter(e -> e.equals(r)).forEach(e -> {
String serviceId = serviceId(e);
log.info("Deregister service " + serviceId);
client.deregister(serviceId);
});
this.advertisements.removeIf(e -> e.equals(r));
}
Aggregations