Java Code Examples for com.ecwid.consul.v1.health.model.HealthService#getService()
The following examples show how to use
com.ecwid.consul.v1.health.model.HealthService#getService() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsulServerContext.java From pampas with Apache License 2.0 | 5 votes |
private static String findHost(HealthService healthService) { HealthService.Service service = healthService.getService(); HealthService.Node node = healthService.getNode(); if (StringUtils.isNotBlank(service.getAddress())) { return service.getAddress(); } else if (StringUtils.isNotBlank(node.getAddress())) { return node.getAddress(); } return node.getNode(); }
Example 2
Source File: ConsulClient.java From saluki with Apache License 2.0 | 5 votes |
public ConsulServiceResp lookupHealthService(String serviceName, long lastConsulIndex) { QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex); Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams); if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) { List<HealthService> HealthServices = orgResponse.getValue(); List<ConsulService> ConsulServcies = Lists.newArrayList(); for (HealthService orgService : HealthServices) { Service org = orgService.getService(); ConsulService newService = ConsulService.newSalukiService()// .withAddress(org.getAddress())// .withName(org.getService())// .withId(org.getId())// .withPort(org.getPort().toString())// .withTags(org.getTags())// .build(); ConsulServcies.add(newService); } if (!ConsulServcies.isEmpty()) { ConsulServiceResp response = ConsulServiceResp.newResponse()// .withValue(ConsulServcies)// .withConsulIndex(orgResponse.getConsulIndex())// .withConsulLastContact(orgResponse.getConsulLastContact())// .withConsulKnowLeader(orgResponse.isConsulKnownLeader())// .build(); return response; } } return null; }
Example 3
Source File: ConsulRegistry.java From dubbox with Apache License 2.0 | 5 votes |
private void doNotify(URL url, Collection<NotifyListener> listeners) { List<URL> result = new ArrayList<URL>(); String consumerService = url.getServiceInterface(); try { Response<List<HealthService>> response = this.consulClient.getHealthServices(consumerService, true, QueryParams.DEFAULT); List<HealthService> healthServices = (List<HealthService>) response.getValue(); Iterator<HealthService> iterator = healthServices.iterator(); while (iterator.hasNext()) { HealthService healthService = (HealthService) iterator.next(); HealthService.Service service = healthService.getService(); List<URL> urls = new ArrayList<URL>(); String serviceURL = URL.decode(service.getAddress()); URL u = URL.valueOf(serviceURL); if (UrlUtils.isMatch(url, u)) { urls.add(u); } result.addAll(urls); if (logger.isInfoEnabled()) { logger.info("Consul notify: = " + urls); } } if (result == null || result.size() == 0) { return; } for (NotifyListener listener : listeners) { notify(url, listener, result); } } catch (OperationException e) { throw e; } }
Example 4
Source File: ConsulHelper.java From dyno with Apache License 2.0 | 5 votes |
public static String findHost(HealthService healthService) { HealthService.Service service = healthService.getService(); HealthService.Node node = healthService.getNode(); if (StringUtils.isNotBlank(service.getAddress())) { return service.getAddress(); } else if (StringUtils.isNotBlank(node.getAddress())) { return node.getAddress(); } return node.getNode(); }
Example 5
Source File: ConsulServerUtils.java From spring-cloud-consul with Apache License 2.0 | 5 votes |
public static String findHost(HealthService healthService) { HealthService.Service service = healthService.getService(); HealthService.Node node = healthService.getNode(); if (StringUtils.hasText(service.getAddress())) { return fixIPv6Address(service.getAddress()); } else if (StringUtils.hasText(node.getAddress())) { return fixIPv6Address(node.getAddress()); } return node.getNode(); }