SpringCloud 服务注册

2023-06-08 10:25 更新

Commons现在提供一个​​ServiceRegistry​​接口,该接口提供诸如​​register(Registration)​​和​​deregister(Registration)​​之类的方法,这些方法使您可以提供自定义的注册服务。​​Registration​​是标记界面。

以下示例显示了正在使用的​​ServiceRegistry​​:

@Configuration
@EnableDiscoveryClient(autoRegister=false)
public class MyConfiguration {
    private ServiceRegistry registry;

    public MyConfiguration(ServiceRegistry registry) {
        this.registry = registry;
    }

    // called through some external process, such as an event or a custom actuator endpoint
    public void register() {
        Registration registration = constructRegistration();
        this.registry.register(registration);
    }
}

每个​​ServiceRegistry​​实现都有自己的​Registry​实现。

  • ​​ZookeeperRegistration​​与​​ZookeeperServiceRegistry​​一起使用
  • ​​EurekaRegistration​​与​​EurekaServiceRegistry​​一起使用
  • ​ConsulRegistration​​与​​ConsulServiceRegistry​​一起使用

如果您使用的是​​ServiceRegistry​​接口,则将需要为使用的​​ServiceRegistry​​实现传递正确的​​Registry​​实现。


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号