public GrpcNameResolver(URI targetUri, Attributes params, GrpcURL subscribeUrl) { GrpcURL registryUrl = GrpcURL.valueOf(targetUri.toString()); this.registry = RegistryProvider.asFactory().newRegistry(registryUrl); this.subscribeUrl = subscribeUrl; }
public GrpcURL getUrlParameter(String key) { GrpcURL u = getUrls().get(key); if (u != null) { return u; } String value = getParameterAndDecoded(key); if (value == null || value.length() == 0) { return null; } u = GrpcURL.valueOf(value); getUrls().put(key, u); return u; }
private GrpcURL buildURL(ConsulService service) { try { for (String tag : service.getTags()) { if (StringUtils.indexOf(tag, Constants.PROVIDERS_CATEGORY) != -1) { String toUrlPath = StringUtils.substringAfter(tag, Constants.PROVIDERS_CATEGORY); GrpcURL salukiUrl = GrpcURL.valueOf(GrpcURL.decode(toUrlPath)); return salukiUrl; } } } catch (Exception e) { log.error("convert consul service to url fail! service:" + service, e); } return null; }
public static String filterLocalHost(String host) { if (host == null || host.length() == 0) { return host; } if (host.contains("://")) { GrpcURL u = GrpcURL.valueOf(host); if (NetUtils.isInvalidLocalHost(u.getHost())) { return u.setHost(NetUtils.getLocalHost()).toFullString(); } } else if (host.contains(":")) { int i = host.lastIndexOf(':'); if (NetUtils.isInvalidLocalHost(host.substring(0, i))) { return NetUtils.getLocalHost() + host.substring(i); } } else { if (NetUtils.isInvalidLocalHost(host)) { return NetUtils.getLocalHost(); } } return host; }
/** * ==============help method============= */ private Triple<String, String, String> getmachineInfo(String providerAndConsumerKv, String groupService) { String thralUrl = consulClient.getKVValue(providerAndConsumerKv).getValue().getDecodedValue(); GrpcURL url = GrpcURL.valueOf(thralUrl); String flagAndIp = StringUtils.remove(providerAndConsumerKv, groupService + "/"); String[] serverInfos = StringUtils.split(flagAndIp, "/"); String machineFlag = serverInfos[1]; return new ImmutableTriple<String, String, String>(machineFlag, url.getAddress(), url.getParameter(Constants.HTTP_PORT_KEY)); } private Triple<String, String, String> getPortHostService(String serviceId) {