本文整理汇总了Java中com.orbitz.consul.AgentClient类的典型用法代码示例。如果您正苦于以下问题:Java AgentClient类的具体用法?Java AgentClient怎么用?Java AgentClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AgentClient类属于com.orbitz.consul包,在下文中一共展示了AgentClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: register
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
@Override
public void register() throws SysException {
AgentClient agentClient = buildConsul().agentClient();
try {
String check = config.getConsul("check");
String serviceId = config.getConsul("serviceId");
String serviceName = config.getConsul("serviceName");
int port = Integer.parseInt(config.getConsul("port"));
long ttl = Long.parseLong(config.getConsul("ttl"));
agentClient.register(port, URI.create(check).toURL(), ttl, serviceName, serviceId);
} catch (Exception e) {
throw new SysException(e);
}
}
示例2: advertise
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
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());
}
示例3: deregister
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
/**
* Deregister a service from Consul
*/
public void deregister() {
final AgentClient agent = consul.agentClient();
if (!agent.isRegistered(serviceId)) {
LOGGER.info("No service registered with ID \"{}\"", serviceId);
return;
}
LOGGER.info("Deregistering service ID \"{}\"", serviceId);
try {
consul.agentClient().deregister(serviceId);
} catch (ConsulException e) {
LOGGER.error("Failed to deregister service from Consul", e);
}
}
示例4: advertise
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
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);
}
示例5: registerMyself
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
private void registerMyself() throws NotRegisteredException, IOException {
AgentClient agentClient = getConsul().agentClient();
if (!agentClient.isRegistered(consulProperties.getServiceId())) {
registerHeartbeat();
}
log.info("writing service access properties");
KeyValueClient kvClient = getConsul().keyValueClient();
Map<String, String> accessProperties = new HashMap<>();
String serverName = InetAddress.getLocalHost().getHostName();
accessProperties.put("hostname", serverName);
accessProperties.put("ip", dnsResolver.readNonLoopbackLocalAddress());
String port = String.valueOf(serverProperties.getPort());
accessProperties.put("port", port);
accessProperties.put("username", securityProperties.getUser().getName());
accessProperties.put("password", securityProperties.getUser().getPassword());
// read current access values and add ourselves
String accessKey = consulProperties.getServiceName() + "/access/" + serverName + ":" + port;
kvClient.putValue(accessKey, mapper.writeValueAsString(accessProperties));
}
示例6: configure
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
@Override
public void configure(final Binder binder) {
loading();
cfgs.forEach((id, cfg) -> {
final Consul consul = build(cfg);
binder.bind(Consul.class).annotatedWith(Names.named(CONSUL_PREFIX + id)).toInstance(consul);
binder.bind(AgentClient.class).annotatedWith(Names.named(CONSUL_AGENT_CLIENT_PREFIX + id)).toInstance(consul.agentClient());
binder.bind(HealthClient.class).annotatedWith(Names.named(CONSUL_HEALTH_CLIENT_PREFIX + id)).toInstance(consul.healthClient());
binder.bind(KeyValueClient.class).annotatedWith(Names.named(CONSUL_KEY_VALUE_CLIENT_PREFIX + id)).toInstance(consul.keyValueClient());
binder.bind(CatalogClient.class).annotatedWith(Names.named(CONSUL_CATALOG_CLIENT_PREFIX + id)).toInstance(consul.catalogClient());
binder.bind(StatusClient.class).annotatedWith(Names.named(CONSUL_STATUS_CLIENT_PREFIX + id)).toInstance(consul.statusClient());
binder.bind(SessionClient.class).annotatedWith(Names.named(CONSUL_SESSION_CLIENT_PREFIX + id)).toInstance(consul.sessionClient());
binder.bind(EventClient.class).annotatedWith(Names.named(CONSUL_EVENT_CLIENT_PREFIX + id)).toInstance(consul.eventClient());
binder.bind(PreparedQueryClient.class).annotatedWith(Names.named(CONSUL_PREPARED_QUERY_CLIENT_PREFIX + id))
.toInstance(consul.preparedQueryClient());
binder.bind(CoordinateClient.class).annotatedWith(Names.named(CONSUL_COORDINATE_CLIENT_PREFIX + id))
.toInstance(consul.coordinateClient());
binder.bind(OperatorClient.class).annotatedWith(Names.named(CONSUL_OPERATOR_CLIENT + id)).toInstance(consul.operatorClient());
});
}
示例7: deregister
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
@Override
public void deregister() throws SysException {
AgentClient agentClient = buildConsul().agentClient();
try {
agentClient.deregister(config.getConsul("serviceId"));
} catch (Exception e) {
throw new SysException(e);
}
}
示例8: register
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
@Override
public void register() throws SysException {
try {
AgentClient agentClient = buildConsul().agentClient();
agentClient.register(Configurer.port, URI.create(Configurer.check).toURL(), Configurer.ttl,
Configurer.serviceName, Configurer.serviceId);
} catch (Exception e) {
throw new SysException(e);
}
}
示例9: deregister
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
@Override
public void deregister() throws SysException {
try {
AgentClient agentClient = buildConsul().agentClient();
agentClient.deregister(Configurer.serviceId);
} catch (Exception e) {
throw new SysException(e);
}
}
示例10: register
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
private static void register() {
AgentClient agentClient = consul.agentClient();
List<Registration.RegCheck> checks = new ArrayList<Registration.RegCheck>();
HostAndPort serviceHostAndPort = HostAndPort.fromParts(visibleHost, visiblePort);
Registration.RegCheck mainCheck = Registration.RegCheck.tcp(serviceHostAndPort.toString(), 30);
checks.add(mainCheck);
Registration registration = ImmutableRegistration
.builder()
.port(visiblePort)
.address(visibleHost)
.checks(checks)
.name(serviceName)
.id(serviceId)
.addTags(tsdMode)
.build();
agentClient.register(registration);
if (agentClient.isRegistered(serviceId)) {
LOGGER.info("Registered this instance with Consul");
} else {
LOGGER.warn("Consul reports that this instance is not registered");
}
}
示例11: activate
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {
ServiceTarget target = context.getServiceTarget();
ConsulService consul = new ConsulService(this.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();
}
示例12: unadvertise
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
public void unadvertise(String name, String address, int port) {
AgentClient client = this.agentClientInjector.getValue();
this.advertisements
.stream()
.forEach(e -> {
String serviceId = serviceId(e);
log.info("Deregister service " + serviceId);
client.deregister(serviceId);
});
this.advertisements.removeIf(e -> e.getName().equals(name) && e.getAddress().equals(address) && e.getPort() == port);
}
示例13: activate
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
@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();
}
示例14: unadvertise
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
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));
}
示例15: getValue
import com.orbitz.consul.AgentClient; //导入依赖的package包/类
@Override
public AgentClient getValue() throws IllegalStateException, IllegalArgumentException {
return this.client;
}