此版本仍在开发中,尚未被视为稳定版本。如需最新的稳定版本,请使用 Spring Cloud Zookeeper 4.2.0! |
Spring Cloud Zookeeper 和服务注册表
Spring Cloud Zookeeper 实现了ServiceRegistry
界面, 让开发人员
以编程方式注册任意服务。
这ServiceInstanceRegistration
class 提供builder()
方法创建Registration
对象,该对象可由ServiceRegistry
,如下所示
例:
@Autowired
private ZookeeperServiceRegistry serviceRegistry;
public void registerThings() {
ZookeeperRegistration registration = ServiceInstanceRegistration.builder()
.defaultUriSpec()
.address("anyUrl")
.port(10)
.name("/a/b/c/d/anotherservice")
.build();
this.serviceRegistry.register(registration);
}
实例状态
Netflix Eureka 支持具有以下OUT_OF_SERVICE
已在 服务器中注册。
这些实例不会作为活动服务实例返回。
这对于蓝/绿部署等行为非常有用。
(请注意,Curator Service Discovery 配方不支持此行为。利用灵活的有效负载,Spring Cloud Zookeeper 实现了OUT_OF_SERVICE
通过更新一些特定的元数据,然后在 Spring Cloud LoadBalancer 中过滤该元数据ZookeeperServiceInstanceListSupplier
.
这ZookeeperServiceInstanceListSupplier
筛选掉所有不等于UP
.
如果实例状态字段为空,则认为UP
以实现向后兼容性。
要更改实例的状态,请创建POST
跟OUT_OF_SERVICE
到ServiceRegistry
Instance Status Actuator 端点,如以下示例所示:
$ http POST http://localhost:8081/serviceregistry status=OUT_OF_SERVICE
前面的示例使用http 命令 httpie.org。 |