(转)聊聊eureka|(转)聊聊eureka instance的overriddenstatus

来源于微信:码匠的流水账

【(转)聊聊eureka|(转)聊聊eureka instance的overriddenstatus】本文主要研究一下eureka instance的overriddenstatus
overriddenstatus
eureka-client-1.8.8-sources.jar!/com/netflix/appinfo/InstanceInfo.java

/** * Sets the status overridden by some other external process.This is * mostly used in putting an instance out of service to block traffic to * it. * * @param status the overridden {@link InstanceStatus} of the instance. * @return @return the {@link InstanceInfo} builder. */ public Builder setOverriddenStatus(InstanceStatus status) { result.overriddenstatus = status; return this; }

通过注释可以看到,这个overriddenstatus的意思就是用于外部的一些操作,在netflix里头就是用于red/black部署的时候,先把指定服务设置为OUT_OF_SERVICE来故意关闭请求流量。
public enum InstanceStatus { UP, // Ready to receive traffic DOWN, // Do not send traffic- healthcheck callback failed STARTING, // Just about starting- initializations to be done - do not // send traffic OUT_OF_SERVICE, // Intentionally shutdown for traffic UNKNOWN; public static InstanceStatus toEnum(String s) { if (s != null) { try { return InstanceStatus.valueOf(s.toUpperCase()); } catch (IllegalArgumentException e) { // ignore and fall through to unknown logger.debug("illegal argument supplied to InstanceStatus.valueOf: {}, defaulting to {}", s, UNKNOWN); } } return UNKNOWN; } }

操作
设置OUT_OF_SERVICE
curl -i -X PUT http://localhost:8761/eureka/apps/client1/127.0.0.1:client1:8081/status?value=https://www.it610.com/article/OUT_OF_SERVICE
HTTP/1.1 200
Content-Type: application/xml
Content-Length: 0
Date: Wed, 16 May 2018 06:52:29 GMT
删除OUT_OF_SERVICE
curl -i -X DELETE http://localhost:8761/eureka/apps/client1/127.0.0.1:client1:8081/status
HTTP/1.1 200
Content-Type: application/xml
Content-Length: 0
Date: Wed, 16 May 2018 06:54:30 GM
小结
eureka instance的overriddenstatus对于部署来说非常好用,比如red/black升级,将部分原服务先设置为OUT_OF_SERVICE,停止接收请求,即变为black,之后新部署的服务启动起来,即为red。如果新服务正常,就可以关闭旧服务了,假设新服务出现问题,则立马删除掉新服务,将原有服务的overriddenstatus删除掉,恢复UP,恢复接收流量。

    推荐阅读