此版本仍在开发中,尚未被视为稳定版本。如需最新的稳定版本,请使用 Spring Cloud Zookeeper 4.2.0spring-doc.cadn.net.cn

Spring Cloud Zookeeper 和服务注册表

Spring Cloud Zookeeper 实现了ServiceRegistry界面, 让开发人员 以编程方式注册任意服务。spring-doc.cadn.net.cn

ServiceInstanceRegistrationclass 提供builder()方法创建Registration对象,该对象可由ServiceRegistry,如下所示 例:spring-doc.cadn.net.cn

@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以实现向后兼容性。 要更改实例的状态,请创建POSTOUT_OF_SERVICEServiceRegistryInstance Status Actuator 端点,如以下示例所示:spring-doc.cadn.net.cn

$ http POST http://localhost:8081/serviceregistry status=OUT_OF_SERVICE
前面的示例使用http命令 httpie.org