Search in sources :

Example 1 with ConsulConfiguration

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"));
    }
}
Also used : ConsulConfiguration(org.apache.camel.component.consul.ConsulConfiguration) ServiceDefinition(org.apache.camel.cloud.ServiceDefinition) ServiceDiscovery(org.apache.camel.cloud.ServiceDiscovery) Test(org.junit.Test)

Example 2 with ConsulConfiguration

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()));
        }
    }
}
Also used : ConsulServiceDiscovery(org.apache.camel.component.consul.cloud.ConsulServiceDiscovery) ImmutableRegistration(com.orbitz.consul.model.agent.ImmutableRegistration) Registration(com.orbitz.consul.model.agent.Registration) AgentClient(com.orbitz.consul.AgentClient) ConsulConfiguration(org.apache.camel.component.consul.ConsulConfiguration) ServiceDefinition(org.apache.camel.cloud.ServiceDefinition) ServiceDiscovery(org.apache.camel.cloud.ServiceDiscovery) ConsulServiceDiscovery(org.apache.camel.component.consul.cloud.ConsulServiceDiscovery) Test(org.junit.Test)

Aggregations

ServiceDefinition (org.apache.camel.cloud.ServiceDefinition)2 ServiceDiscovery (org.apache.camel.cloud.ServiceDiscovery)2 ConsulConfiguration (org.apache.camel.component.consul.ConsulConfiguration)2 Test (org.junit.Test)2 AgentClient (com.orbitz.consul.AgentClient)1 ImmutableRegistration (com.orbitz.consul.model.agent.ImmutableRegistration)1 Registration (com.orbitz.consul.model.agent.Registration)1 ConsulServiceDiscovery (org.apache.camel.component.consul.cloud.ConsulServiceDiscovery)1