@RestController
@RequestMapping("/getservices")
public class ServiceController {
@Autowired
private DiscoveryClient discoveryClient;
@GetMapping("/getServicesList")
public Object getServicesList() {
List<List<ServiceInstance>> servicesList = new ArrayList<>();
//获取服务名称
List<String> serviceNames = discoveryClient.getServices();
for (String serviceName : serviceNames) {
//获取服务中的实例列表
List<ServiceInstance> serviceInstances = discoveryClient.getInstances(serviceName);
servicesList.add(serviceInstances);
}
JSONArray jsonArray = new JSONArray(Collections.singletonList(servicesList));
System.out.println("------>"+jsonArray.toString());
return servicesList;
}
[
[
{
"host": "192.168.3.55",
"port": 8723,
"metadata": {},
"uri": "http://192.168.3.55:8723",
"serviceId": "BASICDATA",
"secure": false,
"instanceInfo": {
"instanceId": "192.168.3.55:8723",
"app": "BASICDATA",
"appGroupName": null,
"ipAddr": "192.168.3.55",
"sid": "na",
"homePageUrl": "http://192.168.3.55:8723/",
"statusPageUrl": "http://192.168.3.55:8723/info",
"healthCheckUrl": "http://192.168.3.55:8723/health",
"secureHealthCheckUrl": null,
"vipAddress": "basicData",
"secureVipAddress": "basicData",
"countryId": 1,
"dataCenterInfo": {
"@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
},
"hostName": "192.168.3.55",
"status": "UP",
"leaseInfo": {
"renewalIntervalInSecs": 30,
"durationInSecs": 90,
"registrationTimestamp": 1627259738736,
"lastRenewalTimestamp": 1627302433437,
"evictionTimestamp": 0,
"serviceUpTimestamp": 1627259738736
},
"isCoordinatingDiscoveryServer": false,
"metadata": {},
"lastUpdatedTimestamp": 1627259738736,
"lastDirtyTimestamp": 1627259738676,
"actionType": "ADDED",
"asgName": null,
"overriddenStatus": "UNKNOWN"
}
}
],
[
{
"host": "192.168.3.55",
"port": 9090,
"metadata": {},
"uri": "http://192.168.3.55:9090",
"serviceId": "SYSTEMLOG",
"secure": false,
"instanceInfo": {
"instanceId": "192.168.3.55:9090",
"app": "SYSTEMLOG",
"appGroupName": null,
"ipAddr": "192.168.3.55",
"sid": "na",
"homePageUrl": "http://192.168.3.55:9090/",
"statusPageUrl": "http://192.168.3.55:9090/info",
"healthCheckUrl": "http://192.168.3.55:9090/health",
"secureHealthCheckUrl": null,
"vipAddress": "systemLog",
"secureVipAddress": "systemLog",
"countryId": 1,
"dataCenterInfo": {
"@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
},
"hostName": "192.168.3.55",
"status": "UP",
"leaseInfo": {
"renewalIntervalInSecs": 30,
"durationInSecs": 90,
"registrationTimestamp": 1627259832596,
"lastRenewalTimestamp": 1627302437525,
"evictionTimestamp": 0,
"serviceUpTimestamp": 1627259832596
},
"isCoordinatingDiscoveryServer": false,
"metadata": {},
"lastUpdatedTimestamp": 1627259832596,
"lastDirtyTimestamp": 1627259832563,
"actionType": "ADDED",
"asgName": null,
"overriddenStatus": "UNKNOWN"
}
}
],
[
{
"host": "192.168.3.55",
"port": 9696,
"metadata": {},
"uri": "http://192.168.3.55:9696",
"serviceId": "POLICEMESSAGE",
"secure": false,
"instanceInfo": {
"instanceId": "192.168.3.55:9696",
"app": "POLICEMESSAGE",
"appGroupName": null,
"ipAddr": "192.168.3.55",
"sid": "na",
"homePageUrl": "http://192.168.3.55:9696/",
"statusPageUrl": "http://192.168.3.55:9696/info",
"healthCheckUrl": "http://192.168.3.55:9696/health",
"secureHealthCheckUrl": null,
"vipAddress": "policeMessage",
"secureVipAddress": "policeMessage",
"countryId": 1,
"dataCenterInfo": {
"@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
},
"hostName": "192.168.3.55",
"status": "UP",
"leaseInfo": {
"renewalIntervalInSecs": 30,
"durationInSecs": 90,
"registrationTimestamp": 1627259815714,
"lastRenewalTimestamp": 1627302422239,
"evictionTimestamp": 0,
"serviceUpTimestamp": 1627259815714
},
"isCoordinatingDiscoveryServer": false,
"metadata": {},
"lastUpdatedTimestamp": 1627259815714,
"lastDirtyTimestamp": 1627259815680,
"actionType": "ADDED",
"asgName": null,
"overriddenStatus": "UNKNOWN"
}
}
],
[
{
"host": "192.168.3.55",
"port": 8082,
"metadata": {},
"uri": "http://192.168.3.55:8082",
"serviceId": "WEBPRO",
"secure": false,
"instanceInfo": {
"instanceId": "192.168.3.55:8082",
"app": "WEBPRO",
"appGroupName": null,
"ipAddr": "192.168.3.55",
"sid": "na",
"homePageUrl": "http://192.168.3.55:8082/",
"statusPageUrl": "http://192.168.3.55:8082/info",
"healthCheckUrl": "http://192.168.3.55:8082/health",
"secureHealthCheckUrl": null,
"vipAddress": "WebPro",
"secureVipAddress": "WebPro",
"countryId": 1,
"dataCenterInfo": {
"@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
},
"hostName": "192.168.3.55",
"status": "UP",
"leaseInfo": {
"renewalIntervalInSecs": 30,
"durationInSecs": 90,
"registrationTimestamp": 1627302346148,
"lastRenewalTimestamp": 1627302346148,
"evictionTimestamp": 0,
"serviceUpTimestamp": 1627286514113
},
"isCoordinatingDiscoveryServer": false,
"metadata": {},
"lastUpdatedTimestamp": 1627302346148,
"lastDirtyTimestamp": 1627302346113,
"actionType": "ADDED",
"asgName": null,
"overriddenStatus": "UNKNOWN"
}
}
],
[
{
"host": "192.168.3.55",
"port": 9595,
"metadata": {},
"uri": "http://192.168.3.55:9595",
"serviceId": "DICTIONARY",
"secure": false,
"instanceInfo": {
"instanceId": "192.168.3.55:9595",
"app": "DICTIONARY",
"appGroupName": null,
"ipAddr": "192.168.3.55",
"sid": "na",
"homePageUrl": "http://192.168.3.55:9595/",
"statusPageUrl": "http://192.168.3.55:9595/info",
"healthCheckUrl": "http://192.168.3.55:9595/health",
"secureHealthCheckUrl": null,
"vipAddress": "dictionary",
"secureVipAddress": "dictionary",
"countryId": 1,
"dataCenterInfo": {
"@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
},
"hostName": "192.168.3.55",
"status": "UP",
"leaseInfo": {
"renewalIntervalInSecs": 30,
"durationInSecs": 90,
"registrationTimestamp": 1627259782642,
"lastRenewalTimestamp": 1627302447755,
"evictionTimestamp": 0,
"serviceUpTimestamp": 1627259782642
},
"isCoordinatingDiscoveryServer": false,
"metadata": {},
"lastUpdatedTimestamp": 1627259782642,
"lastDirtyTimestamp": 1627259782610,
"actionType": "ADDED",
"asgName": null,
"overriddenStatus": "UNKNOWN"
}
}
],
[
{
"host": "192.168.3.55",
"port": 8726,
"metadata": {},
"uri": "http://192.168.3.55:8726",
"serviceId": "COMMUNICATION",
"secure": false,
"instanceInfo": {
"instanceId": "192.168.3.55:8726",
"app": "COMMUNICATION",
"appGroupName": null,
"ipAddr": "192.168.3.55",
"sid": "na",
"homePageUrl": "http://192.168.3.55:8726/",
"statusPageUrl": "http://192.168.3.55:8726/info",
"healthCheckUrl": "http://192.168.3.55:8726/health",
"secureHealthCheckUrl": null,
"vipAddress": "communication",
"secureVipAddress": "communication",
"countryId": 1,
"dataCenterInfo": {
"@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
},
"hostName": "192.168.3.55",
"status": "UP",
"leaseInfo": {
"renewalIntervalInSecs": 30,
"durationInSecs": 90,
"registrationTimestamp": 1627259764225,
"lastRenewalTimestamp": 1627302428936,
"evictionTimestamp": 0,
"serviceUpTimestamp": 1627259764225
},
"isCoordinatingDiscoveryServer": false,
"metadata": {},
"lastUpdatedTimestamp": 1627259764225,
"lastDirtyTimestamp": 1627259764193,
"actionType": "ADDED",
"asgName": null,
"overriddenStatus": "UNKNOWN"
}
}
],
[
{
"host": "192.168.3.55",
"port": 8823,
"metadata": {},
"uri": "http://192.168.3.55:8823",
"serviceId": "NETTYCOMMUNICATION",
"secure": false,
"instanceInfo": {
"instanceId": "192.168.3.55:8823",
"app": "NETTYCOMMUNICATION",
"appGroupName": null,
"ipAddr": "192.168.3.17",
"sid": "na",
"homePageUrl": "http://192.168.3.55:8823/",
"statusPageUrl": "http://192.168.3.55:8823/info",
"healthCheckUrl": "http://192.168.3.55:8823/health",
"secureHealthCheckUrl": null,
"vipAddress": "nettycommunication",
"secureVipAddress": "nettycommunication",
"countryId": 1,
"dataCenterInfo": {
"@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
"name": "MyOwn"
},
"hostName": "192.168.3.55",
"status": "UP",
"leaseInfo": {
"renewalIntervalInSecs": 30,
"durationInSecs": 90,
"registrationTimestamp": 1627298054656,
"lastRenewalTimestamp": 1627302448684,
"evictionTimestamp": 0,
"serviceUpTimestamp": 1627287836443
},
"isCoordinatingDiscoveryServer": false,
"metadata": {},
"lastUpdatedTimestamp": 1627298054656,
"lastDirtyTimestamp": 1627298055183,
"actionType": "ADDED",
"asgName": null,
"overriddenStatus": "UNKNOWN"
}
}
]
]