• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java CatalogService类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.orbitz.consul.model.catalog.CatalogService的典型用法代码示例。如果您正苦于以下问题:Java CatalogService类的具体用法?Java CatalogService怎么用?Java CatalogService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CatalogService类属于com.orbitz.consul.model.catalog包,在下文中一共展示了CatalogService类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: buildConnectionString

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
private static String buildConnectionString(List<CatalogService> serviceList) {
    StringBuilder stringBuilder = new StringBuilder();

    Iterator<CatalogService> serviceListIterator = serviceList.iterator();
    while (serviceListIterator.hasNext()) {
        CatalogService serviceNode = serviceListIterator.next();

        stringBuilder
                .append(serviceNode.getServiceAddress())
                .append(":")
                .append(serviceNode.getServicePort());

        if (serviceListIterator.hasNext()) {
            stringBuilder.append(",");
        }
    }

    return stringBuilder.toString();
}
 
开发者ID:inst-tech,项目名称:opentsdb-plugins,代码行数:20,代码来源:ConsulPlugin.java


示例2: getServiceNodes

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的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;
    }
}
 
开发者ID:inst-tech,项目名称:opentsdb-plugins,代码行数:11,代码来源:ConsulPlugin.java


示例3: updateZookeeperQuorum

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
private static void updateZookeeperQuorum(final Config config) {
    String zkQuorum;
    List<CatalogService> zookeeperService = null;

    zookeeperService = getServiceNodes("zookeeper-2181");
    if (zookeeperService.size() > 0) {
        zkQuorum = buildConnectionString(zookeeperService);
        LOGGER.info("Updated Zookeeper Quorum to " + zkQuorum);
        config.overrideConfig("tsd.storage.hbase.zk_quorum", zkQuorum);
    } else {
        LOGGER.info("Unable to locate zookeeper-2181 in Consul");
    }
}
 
开发者ID:inst-tech,项目名称:opentsdb-plugins,代码行数:14,代码来源:ConsulPlugin.java


示例4: getUpdatedListOfServers

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
@Override
public List<ServiceCallServer> getUpdatedListOfServers(String name) {
    List<CatalogService> services = getCatalogClient()
        .getService(name, getCatalogOptions())
        .getResponse();

    List<ServiceHealth> healths = getHealthClient()
        .getAllServiceInstances(name, getCatalogOptions())
        .getResponse();

    return services.stream()
        .filter(service -> !hasFailingChecks(service, healths))
        .map(this::newServer)
        .collect(Collectors.toList());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:ConsulServiceCallServerListStrategies.java


示例5: getMembers

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
/**
 * Get a list of all members.
 * 
 * @return a collection with all members
 */
@Override
protected Collection<String> getMembers() {

    Collection<String> list = new LinkedList<>();
    String name = consulConfig.getName();
    try {

        ConsulResponse<List<CatalogService>> service = this.agentClient.getService(name);

        logger.info("Resolving service: " + name);

        for (CatalogService s : service.getResponse()) {
            if (logger.isFinestEnabled()) {
                logger.finest("Found service at: " + s.getAddress());
            }
            list.add(s.getAddress());
        }

        if (list.isEmpty()) {
            logger.info("No services found!");
        }
        return list;
    } catch (Exception e) {
        logger.warning(e);
        throw ExceptionUtil.rethrow(e);
    }
}
 
开发者ID:decoomanj,项目名称:hazelcast-consul,代码行数:33,代码来源:ConsulJoiner.java


示例6: discoverNodes

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
@Override
public Collection<DiscoveredNode> discoverNodes() {

    Collection<DiscoveredNode> list = new LinkedList<>();
    Properties empty = new Properties();

    if (this.agentClient != null) {
        try {

            ConsulResponse<List<CatalogService>> service = this.agentClient.getService(serviceName);

            LOG.log(Level.WARNING, "Resolving service: {0}", serviceName);

            for (CatalogService s : service.getResponse()) {
                if (LOG.isLoggable(Level.FINEST)) {
                    LOG.log(Level.FINEST, "Found service at: {0}", s.getAddress());
                }
                Address address = new Address(s.getAddress(), s.getServicePort());
                list.add(new SimpleDiscoveredNode(address, empty));
            }

            if (list.isEmpty()) {
                LOG.warning("No consul instances found!");
            }
            return list;
        } catch (Exception e) {
            LOG.severe(e.getMessage());
            throw ExceptionUtil.rethrow(e);
        }
    }
    return list;
}
 
开发者ID:decoomanj,项目名称:hazelcast-consul-spi,代码行数:33,代码来源:ConsulDiscovery.java


示例7: discoverNodes

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
/**
 * Look in consul for nodes with a given name. Exceptions are not rethrown
 * to prevent HazelCast of shutting down. This method returns an empty
 * list in case of error. When for example, consul returns to a normal state
 * a list of nodes is returned. HazelCast will try to connect to this
 * nodes.
 * 
 * @return A Collection of Nodes.
 */
@Override
public Collection<DiscoveryNode> discoverNodes() {

    Collection<DiscoveryNode> list = new LinkedList<>();
    try {

        ConsulResponse<List<CatalogService>> service
                = this.getClient().getService(serviceName);

        for (CatalogService s : service.getResponse()) {
            if (LOG.isLoggable(Level.FINEST)) {
                LOG.log(Level.FINEST, "Found service at: {0}", s.getAddress());
            }
            Address address = new Address(s.getAddress(), s.getServicePort());
            list.add(new SimpleDiscoveryNode(address));
        }

        LOG.log(Level.INFO, "Hazelcast found ''{0}'' instance(s) of ''{1}'' ", new Object[]{list.size(), serviceName});

        return list;
        
    } catch (Exception e) {
        // The exception is no longer rethrown. When the exception
        // arrives in Hazelcast-core, it will stop working totally.
        // An empty list is delivered as default. This method will be
        // invoked again after a certain time. When consul is available,
        // it will answer, otherwise we just retry.
        LOG.severe(e.getMessage());
    }

    return list;
}
 
开发者ID:Neofonie,项目名称:hazelcast-consul-discovery,代码行数:42,代码来源:ConsulDiscovery.java


示例8: resolveByName

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的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;
}
 
开发者ID:amirkibbar,项目名称:plum,代码行数:11,代码来源:Consul4Spring.java


示例9: _discover

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的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;
}
 
开发者ID:bitsofinfo,项目名称:docker-discovery-registrator-consul,代码行数:74,代码来源:ServiceNameStrategyBase.java


示例10: isCheckOnService

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
protected boolean isCheckOnService(ServiceHealth check, CatalogService service) {
    return check.getService().getService().equalsIgnoreCase(service.getServiceName());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:ConsulServiceCallServerListStrategy.java


示例11: hasFailingChecks

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
protected boolean hasFailingChecks(CatalogService service, List<ServiceHealth> healths) {
    return healths.stream().anyMatch(health -> isCheckOnService(health, service) && isNotHealthy(health));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:ConsulServiceCallServerListStrategy.java


示例12: newServer

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
protected ServiceCallServer newServer(CatalogService service) {
    return new DefaultServiceCallServer(
        service.getServiceAddress(),
        service.getServicePort()
    );
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:7,代码来源:ConsulServiceCallServerListStrategy.java


示例13: discoverNodes

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
@Override
public Iterable<DiscoveryNode> discoverNodes() {
	
	List<DiscoveryNode> toReturn = new ArrayList<DiscoveryNode>();
	
	try {
		// discover healthy nodes only? (and its NOT the first invocation...)
		if (this.consulHealthyOnly && discoverNodesInvoked) {
			
			List<ServiceHealth> nodes = consulHealthClient.getHealthyServiceInstances(consulServiceName, ConsulUtility.getAclToken(this.consulAclToken)).getResponse();
			
			for (ServiceHealth node : nodes) {
				toReturn.add(new SimpleDiscoveryNode(
								new Address(node.getService().getAddress(),node.getService().getPort())));
				getLogger().info("Discovered healthy node: " + node.getService().getAddress()+":"+node.getService().getPort());
			}
			
		// discover all services, regardless of health or this is the first invocation
		} else {
			
			ConsulResponse<List<CatalogService>> response = this.consulCatalogClient.getService(consulServiceName, ConsulUtility.getAclToken(this.consulAclToken));
			
			for (CatalogService service : response.getResponse()) {
				
				String discoveredAddress = null;
				String rawServiceAddress = service.getServiceAddress();
				String rawAddress = service.getAddress();
				
				if (rawServiceAddress != null && !rawServiceAddress.trim().isEmpty()) {
				    discoveredAddress = rawServiceAddress;
					
				} else if (rawAddress != null && !rawAddress.trim().isEmpty()) {
				    getLogger().warning("discoverNodes() ServiceAddress was null/blank! " +
						     "for service: " + service.getServiceName() + 
						     " falling back to Address value");
				    discoveredAddress = rawAddress;
					
				} else {
				    getLogger().warning("discoverNodes() could not discover an address, " +
						     "both ServiceAddress and Address were null/blank! " +
						     "for service: " + service.getServiceName());
				}
				
				toReturn.add(new SimpleDiscoveryNode(
						new Address(discoveredAddress, service.getServicePort())));
				getLogger().info("Discovered healthy node: " + discoveredAddress+":"+service.getServicePort());
			}
		}
		
	} catch(Exception e) {
		getLogger().severe("discoverNodes() unexpected error: " + e.getMessage(),e);
	}

	// flag we were invoked
	discoverNodesInvoked = true;
	
	return toReturn;
}
 
开发者ID:bitsofinfo,项目名称:hazelcast-consul-discovery-spi,代码行数:59,代码来源:ConsulDiscoveryStrategy.java


示例14: resolveByNameAsClusterDefinition

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
@Override
public String resolveByNameAsClusterDefinition(String name) {
    Set<CatalogService> services = resolveByName(name);
    return services.stream().map(cs -> cs.getServiceAddress() + ":" + cs.getServicePort()).collect(joining(","));
}
 
开发者ID:amirkibbar,项目名称:plum,代码行数:6,代码来源:Consul4Spring.java


示例15: resolveByName

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
@Override
public Set<CatalogService> resolveByName(String name) {
    return emptySet();
}
 
开发者ID:amirkibbar,项目名称:plum,代码行数:5,代码来源:NoConsulConfig.java


示例16: resolveByName

import com.orbitz.consul.model.catalog.CatalogService; //导入依赖的package包/类
/**
 * resolves a service by its name
 *
 * @param name the service name to lookup
 * @return a set of unique {@link CatalogService} objects
 */
Set<CatalogService> resolveByName(String name);
 
开发者ID:amirkibbar,项目名称:plum,代码行数:8,代码来源:CatalogResolver.java



注:本文中的com.orbitz.consul.model.catalog.CatalogService类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Client类代码示例发布时间:2022-05-23
下一篇:
Java BeanGenerator类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap