use of org.apache.camel.component.consul.ConsulConfiguration in project camel by apache.
the class ConsulServiceDiscoveryTest method testServiceDiscovery.
// *************************************************************************
// Test
// *************************************************************************
@Test
public void testServiceDiscovery() throws Exception {
ConsulConfiguration configuration = new ConsulConfiguration(null);
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"));
}
}
use of org.apache.camel.component.consul.ConsulConfiguration 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()));
}
}
}
Aggregations