最近在 SpringCloud 项目中发现 Eureka 注册中心的微服务会被异常的 DOWN 掉,但是微服务其实并没有宕机,如果想强行重新上线要如何操作呢?
Eureka Rest接口- 心跳续约
接口地址: /eureka/apps/appID/instanceID
调用方式:PUT
源码地址:com.netflix.eureka.resources.InstanceResource.renewLease()
返回状态:
HTTPCode: 200 为成功
HTTPCode: 404 续约失败,重新注册
接口说明:调用该接口进行心跳续约
调用说明:http://server1:8010/eureka/apps/{微服务名称Application}/{服务instanceID}
1. 强制恢复服务:UP
PUT 请求:
http://server1:8010/eureka/apps/BOOK-SERVICE/book-service-01/status?value=UP
2. 强制下线服务:DOWN
PUT 请求:
http://server1:8010/eureka/apps/BOOK-SERVICE/book-service-01/status?value=DOWN
3. 强制剔除服务:OUT_OF_SERVICE
PUT 请求:
http://server1:8010/eureka/apps/BOOK-SERVICE/book-service-01/status?value=OUT_OF_SERVICE
警告:强制设置后状态将会覆盖真实状态,谨慎操作!!如果需要取消强制设置,将 PUT 请求改为 DELETE 请求即可!!!
For JSON/XML, the content types supplied must be application/xml or application/json.
Operation | HTTP action | Description |
Register new application instance | POST /eureka/v2/apps/appID | Input: JSON/XMLpayload HTTPCode: 204 on success |
De-register application instance | DELETE /eureka/v2/apps/appID/instanceID | HTTP Code: 200 on success |
Send application instance heartbeat | PUT /eureka/v2/apps/appID/instanceID | HTTP Code: * 200 on success * 404 if instanceID doesn’t exist |
Query for all instances | GET /eureka/v2/apps | HTTP Code: 200 on success Output: JSON/XML |
Query for all appID instances | GET /eureka/v2/apps/appID | HTTP Code: 200 on success Output: JSON/XML |
Query for a specific appID/instanceID | GET /eureka/v2/apps/appID/instanceID | HTTP Code: 200 on success Output: JSON/XML |
Query for a specific instanceID | GET /eureka/v2/instances/instanceID | HTTP Code: 200 on success Output: JSON/XML |
Take instance out of service | PUT /eureka/v2/apps/appID/instanceID/status?value=OUT_OF_SERVICE | HTTP Code: * 200 on success * 500 on failure |
Move instance back into service (remove override) | DELETE /eureka/v2/apps/appID/instanceID/status?value=UP (The value=UP is optional, it is used as a suggestion for the fallback status due to removal of the override) | HTTP Code: * 200 on success * 500 on failure |
Update metadata | PUT /eureka/v2/apps/appID/instanceID/metadata?key=value | HTTP Code: * 200 on success * 500 on failure |
Query for all instances under a particular vip address | GET /eureka/v2/vips/vipAddress | * HTTP Code: 200 on success Output: JSON/XML * 404 if the vipAddress does not exist. |
Query for all instances under a particular secure vip address | GET /eureka/v2/svips/svipAddress | * HTTP Code: 200 on success Output: JSON/XML * 404 if the svipAddress does not exist. |