常用api枚举

请求方式url说明
GEThttp://localhost:8761/eureka/apps查询所有应用实例
GEThttp://localhost:8761/eureka/apps/SERVICES2根据 AppId 查询
GEThttp://localhost:8761/eureka/apps/SERVICES2/services2:7f411a785a97590bf4ae5176489e3d15根据 AppId 及 instanceId 查询
GEThttp://localhost:8761/eureka/instances/services2:7f411a785a97590bf4ae5176489e3d15根据 instanceId 查询
DELETEhttp://localhost:8761/eureka/apps/SERVICES3/services3:7f411a785a97590bf4ae9086489e3d15注销应用实例
POSThttp://localhost:8761/eureka/apps/SERVICES2注册新应用实例
PUThttp://localhost:8761/eureka/apps/SERVICES2/services2:7f411a785a97590bf4ae5176489e3d15/status?value=OUT_OF_SERVICE暂停/下线应用实例
PUThttp://localhost:8761/eureka/apps/SERVICES2/services2:7f411a785a97590bf4ae5176489e3d15/status?value=UP恢复应用实例
PUThttp://localhost:8761/eureka/apps/SERVICES2/services2:7f411a785a97590bf4ae5176489e3d15应用实例发送心跳
PUThttp://localhost:8761/eureka/apps/SERVICES2/services2:7f411a785a97590bf4ae5176489e3d15/metadata?version=1.1.1修改应用实例元数据

部分api示例

注册新应用实例

POST http://localhost:8761/eureka/apps/SERVICES3

请求内容格式: application/xml

<instance>
	<instanceId>services3:7f411a785a97590bf4ae9086489e3d15</instanceId>
    <hostName>192.168.1.7</hostName>
	<app>SERVICES3</app>
    <ipAddr>192.168.1.7</ipAddr>
	<status>UP</status>
	<overriddenstatus>UNKNOWN</overriddenstatus>
	<port enabled="true">8083</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>services3</vipAddress>
	<secureVipAddress>demo-order2</secureVipAddress>
	<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
	<lastUpdatedTimestamp>1541584436212</lastUpdatedTimestamp>
	<lastDirtyTimestamp>1541584436212</lastDirtyTimestamp>
</instance>

查询所有应用实例

GET http://localhost:8761/eureka/apps

返回内容

<applications>
    <versions__delta>1</versions__delta>
    <apps__hashcode>UP_2_</apps__hashcode>
    <application>
        <name>SERVICES3</name>
        <instance>
            <instanceId>services3:7f411a785a97590bf4ae9086489e3d15</instanceId>
            <hostName>192.168.1.7</hostName>
            <app>SERVICES3</app>
            <ipAddr>192.168.1.7</ipAddr>
            <status>UP</status>
            <overriddenstatus>UNKNOWN</overriddenstatus>
            <port enabled="true">8083</port>
            <securePort enabled="false">443</securePort>
            <countryId>1</countryId>
            <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
                <name>MyOwn</name>
      
            </dataCenterInfo>
            <leaseInfo>
                <renewalIntervalInSecs>30</renewalIntervalInSecs>
                <durationInSecs>90</durationInSecs>
                <registrationTimestamp>1541585303887</registrationTimestamp>
                <lastRenewalTimestamp>1541585303887</lastRenewalTimestamp>
                <evictionTimestamp>0</evictionTimestamp>
                <serviceUpTimestamp>1541585303383</serviceUpTimestamp>
      
            </leaseInfo>
            <metadata class="java.util.Collections$EmptyMap"/>
            <vipAddress>services3</vipAddress>
            <secureVipAddress>demo-order2</secureVipAddress>
            <isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
            <lastUpdatedTimestamp>1541585303887</lastUpdatedTimestamp>
            <lastDirtyTimestamp>1541584436212</lastDirtyTimestamp>
            <actionType>ADDED</actionType>
    
        </instance>
  
    </application>
    <application>
        <name>SERVICES2</name>
        <instance>
            <instanceId>services2:7f411a785a97590bf4ae5176489e3d15</instanceId>
            <hostName>192.168.1.7</hostName>
            <app>SERVICES2</app>
            <ipAddr>192.168.1.7</ipAddr>
            <status>UP</status>
            <overriddenstatus>UNKNOWN</overriddenstatus>
            <port enabled="true">8082</port>
            <securePort enabled="false">443</securePort>
            <countryId>1</countryId>
            <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
                <name>MyOwn</name>
      
            </dataCenterInfo>
            <leaseInfo>
                <renewalIntervalInSecs>5</renewalIntervalInSecs>
                <durationInSecs>10</durationInSecs>
                <registrationTimestamp>1541584436212</registrationTimestamp>
                <lastRenewalTimestamp>1541585318895</lastRenewalTimestamp>
                <evictionTimestamp>0</evictionTimestamp>
                <serviceUpTimestamp>1541584435699</serviceUpTimestamp>
      
            </leaseInfo>
            <metadata>
                <zone>primary</zone>
                <profile>dev</profile>
                <version></version>
      
            </metadata>
            <homePageUrl>http://192.168.1.7:8082/</homePageUrl>
            <statusPageUrl>http://192.168.1.7:8082/management/info</statusPageUrl>
            <healthCheckUrl>http://192.168.1.7:8082/management/health</healthCheckUrl>
            <vipAddress>services2</vipAddress>
            <secureVipAddress>services2</secureVipAddress>
            <isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
            <lastUpdatedTimestamp>1541584436212</lastUpdatedTimestamp>
            <lastDirtyTimestamp>1541584435194</lastDirtyTimestamp>
            <actionType>ADDED</actionType>
    
        </instance>
  
    </application>
</applications>

修改应用实例元数据

PUT http://localhost:8761/eureka/apps/SERVICES2/services2:7f411a785a97590bf4ae5176489e3d15/metadata?version=1.1.1

version 就为一个元数据。
修改后:

<application>
    <name>SERVICES2</name>
    <instance>
        <instanceId>services2:7f411a785a97590bf4ae5176489e3d15</instanceId>
        <hostName>192.168.1.7</hostName>
        <app>SERVICES2</app>
        <ipAddr>192.168.1.7</ipAddr>
        <status>UP</status>
        <overriddenstatus>UNKNOWN</overriddenstatus>
        <port enabled="true">8082</port>
        <securePort enabled="false">443</securePort>
        <countryId>1</countryId>
        <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
            <name>MyOwn</name>
    
        </dataCenterInfo>
        <leaseInfo>
            <renewalIntervalInSecs>5</renewalIntervalInSecs>
            <durationInSecs>10</durationInSecs>
            <registrationTimestamp>1541586087528</registrationTimestamp>
            <lastRenewalTimestamp>1541586100258</lastRenewalTimestamp>
            <evictionTimestamp>0</evictionTimestamp>
            <serviceUpTimestamp>1541585553811</serviceUpTimestamp>
    
        </leaseInfo>
        <metadata>
            <zone>primary</zone>
            <profile>dev</profile>
            <!--元数据version改成了1.1.1-->
            <version>1.1.1</version>
    
        </metadata>
        <homePageUrl>http://192.168.1.7:8082/</homePageUrl>
        <statusPageUrl>http://192.168.1.7:8082/management/info</statusPageUrl>
        <healthCheckUrl>http://192.168.1.7:8082/management/health</healthCheckUrl>
        <vipAddress>services2</vipAddress>
        <secureVipAddress>services2</secureVipAddress>
        <isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
        <lastUpdatedTimestamp>1541586087528</lastUpdatedTimestamp>
        <lastDirtyTimestamp>1541585847570</lastDirtyTimestamp>
        <actionType>ADDED</actionType>
  
    </instance>
</application>

源码实现

eureka server 用到了jersey实现api功能,其中包含了子资源路由api功能。具体可以参考 https://blog.csdn.net/qq_30062125/article/details/83758334

Logo

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

更多推荐