REST API 介绍

  Eureka 在 GitHub 的 wiki 上专门写了一篇《 Eureka REST operations》来介绍 Eureka Server 的 REST API 接口,Spring Cloud Netfix Eureka 跟 Spring Boot 适配之后,提供的 REST API 与原始的 REST API 有一点点不同,其路径中的 {version} 值固定为 eureka,其他的变化不大,如下图所示:

Eureka Server REST API

Eureka Server REST API

REST API 实战

查询所有应用实例

  • http://localhost:8761/eureka/apps

查询所有应用实例

根据 AppId 查询

  • http://localhost:8761/eureka/apps/demo-order

根据 AppId 查询

根据 AppId 及 instanceId 查询

  • http://localhost:8761/eureka/apps/demo-order/guoqingsongmbp:demo-order:11100

根据 AppId 及 instanceId 查询

根据 instanceId 查询

  • http://localhost:8761/eureka/instances/guoqingsongmbp:demo-order:11100

根据 instanceId 查询

注册新应用实例

  • http://localhost:8761/eureka/apps/demo-order2

  请求体参数(XML 格式):

<instance>
	<instanceId>demo-order2:11101</instanceId>
    <hostName>127.0.0.1</hostName>
	<app>DEMO-ORDER2</app>
    <ipAddr>127.0.0.1</ipAddr>
	<status>UP</status>
	<overriddenstatus>UNKNOWN</overriddenstatus>
	<port enabled="true">11101</port>
	<securePort enabled="false">443</securePort>
	<countryId>1</countryId>
	<dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
	    <name>MyOwn</name>
	</dataCenterInfo>
	<metadata class="java.util.Collections$EmptyMap"/>
	<vipAddress>demo-order2</vipAddress>
	<secureVipAddress>demo-order2</secureVipAddress>
	<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
	<lastUpdatedTimestamp>1540186708769</lastUpdatedTimestamp>
	<lastDirtyTimestamp>1540186708747</lastDirtyTimestamp>
</instance>

注册新应用实例

  请求体参数(JSON 格式):

{
	"instance": {
		"instanceId": "demo-order2:11101",
		"app": "demo-order2",
		"appGroutName": null,
		"ipAddr": "127.0.0.1",
		"sid": "na",
		"homePageUrl": null,
		"statusPageUrl": null,
		"healthCheckUrl": null,
		"secureHealthCheckUrl": null,
		"vipAddress": "demo-order2",
		"secureVipAddress": "demo-order2",
		"countryId": 1,
		"dataCenterInfo": {
			"@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo",
			"name": "MyOwn"
		},
		"hostName": "127.0.0.1",
		"status": "UP",
		"leaseInfo": null,
		"isCoordinatingDiscoveryServer": false,
		"lastUpdatedTimestamp": 1529391461000,
		"lastDirtyTimestamp": 1529391461000,
		"actionType": null,
		"asgName": null,
		"overridden_status": "UNKNOWN",
		"port": {
			"$": 11102,
			"@enabled": "false"
		},
		"securePort": {
			"$": 7002,
			"@enabled": "false"
		},
		"metadata": {
			"@class": "java.util.Collections$EmptyMap"
		}
	}
}

注册新应用实例

  • 查看注册中心结果:

Eureka Server

注销应用实例

  • http://localhost:8761/eureka/apps/demo-order2/demo-order2:11101

注销应用实例

暂停/下线应用实例

  • http://localhost:8761/eureka/apps/demo-order2/demo-order2:11101/status?value=OUT_OF_SERVICE

暂停/下线应用实例

  • 查看注册中心:

Eureka Server

恢复应用实例

  • http://localhost:8761/eureka/apps/demo-order2/demo-order2:11101/status?value=UP

恢复应用实例

应用实例发送心跳

  • http://localhost:8761/eureka/apps/demo-order2/demo-order2:11101

应用实例发送心跳

修改应用实例元数据

  • http://localhost:8761/eureka/apps/demo-order2/demo-order2:11101/metadata?profile=canary

修改应用实例元数据

  • 原元数据:

原元数据

  • 修改后的元数据:

修改后的元数据

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐