该版本仍在开发中,尚未被视为稳定。对于最新稳定版,请使用Spring Cloud Zookeeper 5.0.0spring-doc.cadn.net.cn

春云动物园饲养员与服务注册

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

ServiceInstanceRegistration类别提供架构商()创建注册可以被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注册到服务器。 这些实例不会作为活跃服务实例返回。 这对于蓝/绿部署等行为非常有用。 (注意,策展人服务发现的配方不支持此行为。)利用灵活的载荷,Spring Cloud Zookeeper 得以实现OUT_OF_SERVICE通过更新特定元数据,然后在 Spring Cloud 负载均衡器中过滤这些元数据ZookeeperServiceInstanceListSupplier. 这ZookeeperServiceInstanceListSupplier过滤掉所有不等于空的实例状态向上. 如果实例状态字段为空,则视为向上为了向下兼容。 要更改实例状态,请创建发布OUT_OF_SERVICE前往ServiceRegistry实例状态执行器端点,如下例所示:spring-doc.cadn.net.cn

$ http POST http://localhost:8081/serviceregistry status=OUT_OF_SERVICE
前述示例使用了httphttpie.org 的指挥。