Spring Cloud中的Consul的相关配置

在这里主要介绍在Consul的相关配置。在这里使用yml的格式进行配置。

spring:
    cloud:
        consul:
            enabled: true //是否启用consul
            host: ip // consul server的ip地址
            port: 8500 // consul运行的端口号
            ribbon:
                enabled: true //是否启用ribbon进行客户端负载均衡
            config:
                enable: true
            discovery:
                heartbeat: //配置是否进行health check,以及频率
                    enabled: true
                    ttlValue: 10
                enable:true // 是否去发现其他服务
                register:true //是否将自身服务注册到consul中
                tags: tagName //为同名的服务打tag用于区分
                default-query-tag: tagName
                query-passing: true
                preferIpAddress: true

query-passing:config client可以通过配置的url或者服务发现的方式拉取config server的配置。
  如果服务发现的方式来拉取配置,默认情况下ConsulDiscoveryClient获取服务的时候是根据服务id获取所有服务节点,如果获取了down的服务,则会造成拉取配置失败。
  ConsulDiscoveryProperties的默认设置queryPassing=false,即返回所有的服务,包括down掉的。通过配置改为true则可返回所有健康检查通过的服务。
preferIpAddress:ConsulDiscoveryProperties这个类是consul服务发现的配置类。默认情况下preferIpAddress值为false,也就是通过host来进行服务地址的注册和检查,但是当环境不支持host访问时就会出问题,所以需要配置preferIpAddress=true。

猜你喜欢

转载自blog.csdn.net/zhaoruda/article/details/80206896