本文整理汇总了Java中com.orbitz.consul.CatalogClient类的典型用法代码示例。如果您正苦于以下问题:Java CatalogClient类的具体用法?Java CatalogClient怎么用?Java CatalogClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CatalogClient类属于com.orbitz.consul包,在下文中一共展示了CatalogClient类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: discover
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
public Collection<ServiceInfo> discover(CatalogClient catalogClient,
String serviceName,
Collection<Integer> ports,
Collection<String> mustMatchTags) throws Exception {
Collection<ServiceInfo> services = new ArrayList<ServiceInfo>();
// for each port, we need to append the port to the serviceName base
for (Integer port : ports) {
services.addAll(
super._discover(catalogClient, (serviceName+"-"+port.toString()), ports, mustMatchTags)
);
}
return services;
}
开发者ID:bitsofinfo,项目名称:docker-discovery-registrator-consul,代码行数:19,代码来源:MultiServiceNameSinglePortStrategy.java
示例2: configure
import com.orbitz.consul.CatalogClient; //导入依赖的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());
});
}
示例3: getServiceNodes
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
private static List<CatalogService> getServiceNodes(String serviceName) {
try {
CatalogClient catalogClient = consul.catalogClient();
ConsulResponse<List<CatalogService>> serviceResponse = catalogClient.getService(serviceName);
return serviceResponse.getResponse();
} catch (NullPointerException e) {
LOGGER.error("Could not retrieve Consul Catalog Client");
return null;
}
}
示例4: start
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {
ServiceTarget target = startContext.getChildTarget();
CatalogWatcher watcher = new CatalogWatcher();
target.addService(CatalogWatcher.SERVICE_NAME, watcher)
.addDependency(CatalogClientService.SERVICE_NAME, CatalogClient.class, watcher.getCatalogClientInjector())
.addDependency(HealthClientService.SERIVCE_NAME, HealthClient.class, watcher.getHealthClientInjector())
.addDependency(TopologyManager.SERVICE_NAME, TopologyManager.class, watcher.getTopologyManagerInjector())
.install();
}
开发者ID:wildfly-swarm-archive,项目名称:wildfly-swarm-topology-consul,代码行数:14,代码来源:ConsulTopologyConnector.java
示例5: start
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {
ServiceTarget target = startContext.getChildTarget();
CatalogWatcher watcher = new CatalogWatcher();
target.addService(CatalogWatcher.SERVICE_NAME, watcher)
.addDependency(CatalogClientService.SERVICE_NAME, CatalogClient.class, watcher.getCatalogClientInjector())
.addDependency(HealthClientService.SERIVCE_NAME, HealthClient.class, watcher.getHealthClientInjector())
.addDependency(TopologyManagerActivator.SERVICE_NAME, TopologyManager.class, watcher.getTopologyManagerInjector())
.install();
}
示例6: discover
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
public Collection<ServiceInfo> discover(CatalogClient catalogClient,
String serviceName,
Collection<Integer> ports,
Collection<String> mustMatchTags) throws Exception {
return super._discover(catalogClient, serviceName, ports, mustMatchTags);
}
开发者ID:bitsofinfo,项目名称:docker-discovery-registrator-consul,代码行数:9,代码来源:OneServiceNameMultiPortStrategy.java
示例7: getClient
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
/**
* Construct the client to connect to Consul.
*
* @return CatalogClient
* @throws MalformedURLException
*/
private synchronized CatalogClient getClient() throws MalformedURLException {
if (this.catalogClient == null) {
this.catalogClient = Consul.builder().
withUrl(new URL("http", consulHost, consulPort, "")).
build().
catalogClient();
}
return this.catalogClient;
}
示例8: start
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {
ServiceTarget target = startContext.getChildTarget();
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();
AgentClientService agentClient = new AgentClientService();
target.addService(AgentClientService.SERVICE_NAME, agentClient)
.addDependency(ConsulService.SERVICE_NAME, Consul.class, agentClient.getConsulInjector())
.install();
CatalogClientService catalogClient = new CatalogClientService();
target.addService(CatalogClientService.SERVICE_NAME, catalogClient)
.addDependency(ConsulService.SERVICE_NAME, Consul.class, catalogClient.getConsulInjector())
.install();
this.advertiser = new Advertiser();
target.addService(Advertiser.SERVICE_NAME, advertiser)
.addDependency(AgentClientService.SERVICE_NAME, AgentClient.class, advertiser.getAgentClientInjector())
.install();
CatalogWatcher watcher = new CatalogWatcher();
target.addService(CatalogWatcher.SERVICE_NAME, watcher)
.addDependency(CatalogClientService.SERVICE_NAME, CatalogClient.class, watcher.getCatalogClientInjector())
.addDependency(HealthClientService.SERIVCE_NAME, HealthClient.class, watcher.getHealthClientInjector())
.addDependency(TopologyManager.SERVICE_NAME, TopologyManager.class, watcher.getTopologyManagerInjector())
.install();
}
示例9: getValue
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
@Override
public CatalogClient getValue() throws IllegalStateException, IllegalArgumentException {
return this.client;
}
示例10: resolveByName
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
@Override
public Set<CatalogService> resolveByName(String name) {
CatalogClient catalogClient = getConsul().catalogClient();
List<CatalogService> catalogServices = catalogClient.getService(name).getResponse();
Set<CatalogService> result = new TreeSet<>((o1, o2) -> o1.getServiceName().compareToIgnoreCase(o2.getServiceName()));
result.addAll(catalogServices);
return result;
}
示例11: getCatalogClientInjector
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
public Injector<CatalogClient> getCatalogClientInjector() {
return this.catalogClientInjector;
}
示例12: _discover
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
protected Collection<ServiceInfo> _discover(CatalogClient catalogClient,
String serviceName,
Collection<Integer> ports,
Collection<String> mustMatchTags) throws Exception {
List<ServiceInfo> discoveredServices = new ArrayList<ServiceInfo>();
ConsulResponse<List<CatalogService>> resp = catalogClient.getService(serviceName);
List<CatalogService> serviceList = resp.getResponse();
logger.trace("_discover() catalogClient.getService("+serviceName+") returned " + serviceList.size() + " results..");
for (CatalogService srv : serviceList) {
logger.trace("_discover() evaluating consul service: name:" + srv.getServiceName() +
" serviceId:" + srv.getServiceId() +
" servicePort:" + srv.getServicePort() +
" tags: " + Arrays.toString(srv.getServiceTags().toArray()));
if (matchesTags(srv.getServiceTags(),mustMatchTags)) {
try {
// we parse mapped port from serviceId format "xx:yy:port"
// registrator sets the serviceId = to this format above for each
// unique port
int mappedPort = Integer.valueOf(srv.getServiceId().split(":")[2]);
// if we care about this mapped port... capture the service
if (ports.contains(mappedPort)) {
InetAddress exposedAddress = null;
if (srv.getServiceAddress() != null) {
exposedAddress = InetAddress.getByName(srv.getServiceAddress());
} else {
// https://www.consul.io/docs/agent/http/catalog.html#ServiceAddress
logger.trace("_discover() CatalogService.serviceAddress is null... "
+ "falling back to address["+srv.getAddress()+"]");
exposedAddress = InetAddress.getByName(srv.getAddress());
}
ServiceInfo info = new ServiceInfo(srv.getServiceName(),
srv.getServiceId(),
exposedAddress,
srv.getServicePort(),
mappedPort,
srv.getServiceTags());
discoveredServices.add(info);
logger.debug("_discover() Discovered ServiceInfo: " + info);
} else {
logger.trace("_discover() serviceNameToFind=" + serviceName +
", skipping consul service: " + srv.getServiceName() +
" as its mappedPort[" + mappedPort + "] is not in list of "
+ "ports we care about: " + Arrays.toString(ports.toArray()) );;
}
} catch(Exception e) {
throw new Exception("discover() Unexpected error processing "
+ "service: " + srv.getServiceName() + " " + e.getMessage(),e);
}
} else {
logger.trace("_discover() serviceNameToFind=" + serviceName +
" skipping consul service: " + srv.getServiceName() +
" with tags: " + (srv.getServiceTags() != null ? Arrays.toString(srv.getServiceTags().toArray()) : "[no tags]") +
" as they don't contain mustMatchTags: " + Arrays.toString(mustMatchTags.toArray()));
}
}
return discoveredServices;
}
示例13: discover
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
public Collection<ServiceInfo> discover(CatalogClient catalogClient,
String serviceName,
Collection<Integer> ports,
Collection<String> mustMatchTags) throws Exception;
示例14: getCatalogClient
import com.orbitz.consul.CatalogClient; //导入依赖的package包/类
protected CatalogClient getCatalogClient() {
return client.catalogClient();
}