use of org.springframework.cloud.client.ServiceInstance in project micro-service by Lovnx.
the class ComputeController method add.
@RequestMapping(value = "/**", method = RequestMethod.GET)
public String add(@RequestParam Integer a, @RequestParam Integer b, HttpServletRequest request) {
System.out.println(request.getRequestURL());
ServiceInstance instance = client.getLocalServiceInstance();
Integer r = a + b;
logger.info("/add, host:" + instance.getHost() + ", service_id:" + instance.getServiceId() + ", result:" + r);
return "From Service-B, Result is " + r + "\nPort:" + instance.getPort();
}
use of org.springframework.cloud.client.ServiceInstance in project coffeenet-starter by coffeenet.
the class IntegrationCoffeeNetAppServiceTest method getAppsNotOfTypeEurekaServiceInstance.
@Test
public void getAppsNotOfTypeEurekaServiceInstance() {
String frontPageName = "frontpage";
ServiceInstance serviceInstance = mock(ServiceInstance.class);
when(discoveryClientMock.getInstances(frontPageName)).thenReturn(singletonList(serviceInstance));
when(discoveryClientMock.getServices()).thenReturn(singletonList(frontPageName));
AppQuery query = AppQuery.builder().withAppName(frontPageName).build();
Map<String, List<CoffeeNetApp>> coffeeNetApps = coffeeNetAppService.getApps(query);
assertThat(coffeeNetApps.entrySet(), hasSize(0));
}
use of org.springframework.cloud.client.ServiceInstance in project druid by alibaba.
the class MonitorStatService method getAllServiceNodeMap.
/**
* 获取所有服务信息
*
* @return
*/
public Map<String, ServiceNode> getAllServiceNodeMap() {
List<String> services = discoveryClient.getServices();
List<ServiceNode> serviceNodes = new ArrayList<>();
for (String service : services) {
List<ServiceInstance> instances = discoveryClient.getInstances(service);
for (ServiceInstance instance : instances) {
String host = instance.getHost();
String instanceId = instance.getInstanceId();
if (instanceId == null) {
instanceId = instance.getMetadata().get("nacos.instanceId").replaceAll("#", "-").replaceAll("@@", "-");
}
int port = instance.getPort();
String serviceId = instance.getServiceId();
// 根据前端参数采集指定的服务
if (monitorProperties.getApplications().contains(serviceId)) {
ServiceNode serviceNode = new ServiceNode();
serviceNode.setId(instanceId);
serviceNode.setPort(port);
serviceNode.setAddress(host);
serviceNode.setServiceName(serviceId);
serviceNodes.add(serviceNode);
serviceIdMap.put(instanceId, serviceNode);
}
}
}
return serviceNodes.parallelStream().collect(Collectors.toMap(i -> i.getServiceName() + "-" + i.getAddress() + "-" + i.getPort(), Function.identity(), (v1, v2) -> v2));
}
use of org.springframework.cloud.client.ServiceInstance in project druid by alibaba.
the class MonitorStatService method getServiceAllNodeMap.
/**
* 获取指定服务名的所有节点
*
* @param parameters
* @return
*/
public Map<String, ServiceNode> getServiceAllNodeMap(Map<String, String> parameters) {
String requestServiceName = parameters.get("serviceName");
List<String> services = discoveryClient.getServices();
List<ServiceNode> serviceNodes = new ArrayList<>();
for (String service : services) {
List<ServiceInstance> instances = discoveryClient.getInstances(service);
for (ServiceInstance instance : instances) {
String host = instance.getHost();
String instanceId = instance.getInstanceId();
if (instanceId == null) {
instanceId = instance.getMetadata().get("nacos.instanceId").replaceAll("#", "-").replaceAll("@@", "-");
}
int port = instance.getPort();
String serviceId = instance.getServiceId();
// 根据前端参数采集指定的服务
if (serviceId.equalsIgnoreCase(requestServiceName)) {
ServiceNode serviceNode = new ServiceNode();
serviceNode.setId(instanceId);
serviceNode.setPort(port);
serviceNode.setAddress(host);
serviceNode.setServiceName(serviceId);
serviceNodes.add(serviceNode);
serviceIdMap.put(instanceId, serviceNode);
}
}
}
return serviceNodes.parallelStream().collect(Collectors.toMap(i -> i.getServiceName() + "-" + i.getAddress() + "-" + i.getPort(), Function.identity(), (v1, v2) -> v2));
}
use of org.springframework.cloud.client.ServiceInstance in project topcom-cloud by 545314690.
the class HelloController method add.
@RequestMapping(value = "/add")
public int add(int a, int b) {
ServiceInstance instance = client.getLocalServiceInstance();
logger.info("/add:" + instance.getHost() + ",service_id: " + instance.getServiceId());
return a + b;
}
Aggregations