本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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";
}
示例7: resolveMappingsUrl
import org.springframework.cloud.client.ServiceInstance; //導入方法依賴的package包/類
@Override
public String resolveMappingsUrl(ServiceInstance instance) {
return instance.getUri() + "/mappings";
}