Search in sources :

Example 1 with Consul

use of com.orbitz.consul.Consul 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());
}
Also used : ImmutableRegCheck(com.orbitz.consul.model.agent.ImmutableRegCheck) ImmutableRegistration(com.orbitz.consul.model.agent.ImmutableRegistration) AgentClient(com.orbitz.consul.AgentClient) Consul(com.orbitz.consul.Consul)

Example 2 with Consul

use of com.orbitz.consul.Consul 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();
}
Also used : ServiceTarget(org.jboss.msc.service.ServiceTarget) AgentClient(com.orbitz.consul.AgentClient) Consul(com.orbitz.consul.Consul)

Example 3 with Consul

use of com.orbitz.consul.Consul in project ff4j by ff4j.

the class PropertyStoreConsulEmbeddedTest method initPropertyStore.

/**
 * {@inheritDoc}
 */
protected PropertyStore initPropertyStore() {
    Consul c = Consul.builder().withUrl("http://localhost:8800").build();
    ConsulConnection connection = new ConsulConnection(c);
    PropertyStoreConsul consulStore = new PropertyStoreConsul(connection);
    consulStore.importPropertiesFromXmlFile("ff4j.xml");
    return consulStore;
}
Also used : PropertyStoreConsul(org.ff4j.consul.store.PropertyStoreConsul) PropertyStoreConsul(org.ff4j.consul.store.PropertyStoreConsul) Consul(com.orbitz.consul.Consul) ConsulConnection(org.ff4j.consul.ConsulConnection)

Example 4 with Consul

use of com.orbitz.consul.Consul in project ff4j by ff4j.

the class FeatureStoreConsulEmbeddedTest method initStore.

/**
 * {@inheritDoc}
 */
protected FeatureStore initStore() {
    Consul c = Consul.builder().withUrl("http://localhost:8800").build();
    ConsulConnection connection = new ConsulConnection(c);
    FeatureStoreConsul ehcacheStore = new FeatureStoreConsul(connection);
    ehcacheStore.importFeaturesFromXmlFile("ff4j.xml");
    return ehcacheStore;
}
Also used : Consul(com.orbitz.consul.Consul) FeatureStoreConsul(org.ff4j.consul.store.FeatureStoreConsul) FeatureStoreConsul(org.ff4j.consul.store.FeatureStoreConsul) ConsulConnection(org.ff4j.consul.ConsulConnection)

Example 5 with Consul

use of com.orbitz.consul.Consul in project wildfly-swarm by wildfly-swarm.

the class ConsulService method start.

@Override
public void start(StartContext startContext) throws StartException {
    Consul.Builder builder = Consul.builder();
    // pool because of multiple threads.
    ResteasyClientBuilder clientBuilder = new ResteasyClientBuilder();
    clientBuilder = clientBuilder.connectionPoolSize(20);
    builder.withClientBuilder(clientBuilder);
    builder.withUrl(this.url);
    try {
        this.consul = builder.build();
    } catch (Exception e) {
        throw new StartException("Failed to connect consul at " + url, e);
    }
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) StartException(org.jboss.msc.service.StartException) Consul(com.orbitz.consul.Consul) StartException(org.jboss.msc.service.StartException)

Aggregations

Consul (com.orbitz.consul.Consul)6 AgentClient (com.orbitz.consul.AgentClient)2 ConsulConnection (org.ff4j.consul.ConsulConnection)2 RpcURL (com.jim.framework.rpc.common.RpcURL)1 HealthClient (com.orbitz.consul.HealthClient)1 ConsulCache (com.orbitz.consul.cache.ConsulCache)1 ServiceHealthCache (com.orbitz.consul.cache.ServiceHealthCache)1 ServiceHealthKey (com.orbitz.consul.cache.ServiceHealthKey)1 ConsulResponse (com.orbitz.consul.model.ConsulResponse)1 ImmutableRegCheck (com.orbitz.consul.model.agent.ImmutableRegCheck)1 ImmutableRegistration (com.orbitz.consul.model.agent.ImmutableRegistration)1 ImmutableServiceHealth (com.orbitz.consul.model.health.ImmutableServiceHealth)1 ServiceHealth (com.orbitz.consul.model.health.ServiceHealth)1 List (java.util.List)1 FeatureStoreConsul (org.ff4j.consul.store.FeatureStoreConsul)1 PropertyStoreConsul (org.ff4j.consul.store.PropertyStoreConsul)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1 StartException (org.jboss.msc.service.StartException)1 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)1