Spring Cloud Zookeeper 实现了该接口,让开发人员
以编程方式注册任意服务。ServiceRegistry
该类提供了一种方法来创建可由 使用的对象,如下所示
例:ServiceInstanceRegistration
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 支持将实例注册到服务器。
这些实例不会作为活动服务实例返回。
这对于蓝/绿部署等行为很有用。
(请注意,Curator Service Discovery 配方不支持此行为。利用灵活的有效负载,Spring Cloud Zookeeper 可以通过更新一些特定的元数据,然后在 Spring Cloud LoadBalancer 中过滤该元数据来实现。
将筛选出所有不等于 的非 null 实例状态。
如果实例状态字段为空,则认为该字段用于向后兼容。
要更改实例的状态,请对实例状态执行器终端节点进行 WITH,如以下示例所示:OUT_OF_SERVICE
OUT_OF_SERVICE
ZookeeperServiceInstanceListSupplier
ZookeeperServiceInstanceListSupplier
UP
UP
POST
OUT_OF_SERVICE
ServiceRegistry
$ http POST http://localhost:8081/serviceregistry status=OUT_OF_SERVICE
前面的示例使用 httpie.org 中的命令。http |
前面的示例使用 httpie.org 中的命令。http |