當前位置: 首頁>>代碼示例>>Java>>正文


Java ServiceInstance.getUri方法代碼示例

本文整理匯總了Java中org.springframework.cloud.client.ServiceInstance.getUri方法的典型用法代碼示例。如果您正苦於以下問題:Java ServiceInstance.getUri方法的具體用法?Java ServiceInstance.getUri怎麽用?Java ServiceInstance.getUri使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.cloud.client.ServiceInstance的用法示例。


在下文中一共展示了ServiceInstance.getUri方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractServiceMetaData

import org.springframework.cloud.client.ServiceInstance; //導入方法依賴的package包/類
private Map<String, Object> extractServiceMetaData(RouteVM routeVM) {
    Objects.requireNonNull(routeVM,
        "Can't extract service metadata because routeVM is not pass");

    Map<String, String> serviceInstancesStatus = routeVM.getServiceInstancesStatus();
    if (MapUtils.isEmpty(serviceInstancesStatus)) {
        log.error("Microservice instances has no statuses");
        return null;
    }
    Map<String, Object> result = null;
    for (ServiceInstance instance : routeVM.getServiceInstances()) {
        if (instance.getUri() == null || StringUtils.isBlank(instance.getUri().toString())) {
            continue;
        }
        String uri = instance.getUri().toString();
        if ("UP".equals(serviceInstancesStatus.get(uri))) {
            if (result == null) {
                result = new HashMap<>();
            }
            result.put(uri, getInstanceInfo(uri));
        }
    }
    return result;
}
 
開發者ID:xm-online,項目名稱:xm-gate,代碼行數:25,代碼來源:GatewayResource.java

示例2: getOkServer

import org.springframework.cloud.client.ServiceInstance; //導入方法依賴的package包/類
@Override
public Server getOkServer() {

    List<ServiceInstance> serviceInstances =  discoveryClient.getInstances(SOCKET_SERVER_KEY);

    //選取socket服務
    if (serviceInstances != null && serviceInstances.size() > 0 ) {
        for(ServiceInstance instance : serviceInstances){
            URI uri = instance.getUri();
            if (uri !=null ) {
                Server server =  restTemplate.getForObject(uri+"/socket/getServer",Server.class);
                if(server.getNowCount()<=server.getMaxCount()){
                    return server;
                }
            }
        }
    }

    return null;
}
 
開發者ID:1991wangliang,項目名稱:sds,代碼行數:21,代碼來源:DeliveryServerServiceImpl.java

示例3: serverList

import org.springframework.cloud.client.ServiceInstance; //導入方法依賴的package包/類
@Override
public List<Server> serverList() {
    List<ServiceInstance> serviceInstances =  discoveryClient.getInstances(SOCKET_SERVER_KEY);

    List<Server> servers = new ArrayList<>();

    //選取socket服務
    if (serviceInstances != null && serviceInstances.size() > 0 ) {
        for(ServiceInstance instance : serviceInstances){
            URI uri = instance.getUri();
            if (uri !=null ) {
                Server server =  restTemplate.getForObject(uri+"/socket/getServer",Server.class);
                servers.add(server);
            }
        }
    }

    return servers;
}
 
開發者ID:1991wangliang,項目名稱:sds,代碼行數:20,代碼來源:DeliveryServerServiceImpl.java

示例4: getWord

import org.springframework.cloud.client.ServiceInstance; //導入方法依賴的package包/類
public String getWord(String service) {
	ServiceInstance instance = loadBalancer.choose(service);
	if (instance!=null) {
		URI uri = instance.getUri();
		if (uri!=null) {
			return new RestTemplate().getForObject(uri,String.class);
		}
	}
	return null;
}
 
開發者ID:aswroma3,項目名稱:asw,代碼行數:11,代碼來源:SentenceController.java

示例5: getServiceUrl

import org.springframework.cloud.client.ServiceInstance; //導入方法依賴的package包/類
/**
 *
 * @param serviceId
 * @param fallbackUri
 * @return
 */
protected URI getServiceUrl(String serviceId, String fallbackUri) {
    URI uri = null;
    try {
        ServiceInstance instance = loadBalancer.choose(serviceId);

        if (instance == null) {
            throw new RuntimeException("Can't find a service with serviceId = " + serviceId);
        }

        uri = instance.getUri();
        LOG.info("Resolved serviceId '{}' to URL '{}'.", serviceId, uri);

    } catch (RuntimeException e) {
        e.printStackTrace();
        // Eureka not available, use fallback if specified otherwise rethrow the error
        Integer.parseInt("");
        if (fallbackUri == null) {
            throw e;
        } else {
            uri = URI.create(fallbackUri);
            LOG.warn("Failed to resolve serviceId '{}'. Fallback to URL '{}'.", serviceId, uri);
        }
    }

    return uri;
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Microservices-with-Java-9-Second-Edition,代碼行數:33,代碼來源:ServiceHelper.java

示例6: resolveHealthCheckUrl

import org.springframework.cloud.client.ServiceInstance; //導入方法依賴的package包/類
@Override
public String resolveHealthCheckUrl(ServiceInstance instance) {
    return instance.getUri() + "/health";
}
 
開發者ID:ordina-jworks,項目名稱:microservices-dashboard-server,代碼行數:5,代碼來源:DefaultUriResolver.java

示例7: resolveMappingsUrl

import org.springframework.cloud.client.ServiceInstance; //導入方法依賴的package包/類
@Override
public String resolveMappingsUrl(ServiceInstance instance) {
    return instance.getUri() + "/mappings";
}
 
開發者ID:ordina-jworks,項目名稱:microservices-dashboard-server,代碼行數:5,代碼來源:DefaultUriResolver.java


注:本文中的org.springframework.cloud.client.ServiceInstance.getUri方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。