spring-cloud-config集成spring-cloud-bus后执行/bus/refresh不会更新所有节点

spring-cloud-config结合spring-cloud-bus和rabbitmq后执行/bus/refresh不会更新所有节点,只更新了单点。

客户度1:

bootstrap.properties配置

spring.application.name=testConfig
server.port=7002

eureka.client.serviceUrl.defaultZone=http://localhost:7070/eureka/

spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server
spring.cloud.config.profile=test

spring.cloud.config.failFast=true

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

management.security.enabled=false
spring.cloud.bus.trace.enabled=true

pom.xml

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>

对7002端口执行/bus/refresh后client的日志

2017-07-30 09:09:11.302  INFO 30953 --- [nio-7002-exec-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2bc3bf56: startup date [Sun Jul 30 09:09:11 HKT 2017]; root of context hierarchy
2017-07-30 09:09:11.358  INFO 30953 --- [nio-7002-exec-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-07-30 09:09:11.390  INFO 30953 --- [nio-7002-exec-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$14675929] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-07-30 09:09:11.496  INFO 30953 --- [nio-7002-exec-1] o.s.c.n.eureka.InstanceInfoFactory       : Setting initial instance status as: STARTING
2017-07-30 09:09:11.532  INFO 30953 --- [nio-7002-exec-1] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON encoding codec LegacyJacksonJson
2017-07-30 09:09:11.533  INFO 30953 --- [nio-7002-exec-1] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON decoding codec LegacyJacksonJson
2017-07-30 09:09:11.533  INFO 30953 --- [nio-7002-exec-1] c.n.d.provider.DiscoveryJerseyProvider   : Using XML encoding codec XStreamXml
2017-07-30 09:09:11.535  INFO 30953 --- [nio-7002-exec-1] c.n.d.provider.DiscoveryJerseyProvider   : Using XML decoding codec XStreamXml
2017-07-30 09:09:11.627  INFO 30953 --- [nio-7002-exec-1] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration
2017-07-30 09:09:11.628  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Disable delta property : false
2017-07-30 09:09:11.628  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Single vip registry refresh property : null
2017-07-30 09:09:11.628  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Force full registry fetch : false
2017-07-30 09:09:11.628  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Application is null : false
2017-07-30 09:09:11.628  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Registered Applications size is zero : true
2017-07-30 09:09:11.628  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Application version is -1: true
2017-07-30 09:09:11.628  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
2017-07-30 09:09:11.632  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : The response status is 200
2017-07-30 09:09:11.633  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Not registering with Eureka server per configuration
2017-07-30 09:09:11.633  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Discovery Client initialized at timestamp 1501376951633 with initial instances count: 3
2017-07-30 09:09:11.777  INFO 30953 --- [nio-7002-exec-1] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2017-07-30 09:09:11.777  INFO 30953 --- [nio-7002-exec-1] c.n.e.EurekaDiscoveryClientConfiguration : Registering application testConfig with eureka with status UP
2017-07-30 09:09:11.830  INFO 30953 --- [nio-7002-exec-1] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://192.168.3.3:7001/
2017-07-30 09:09:12.621  INFO 30953 --- [nio-7002-exec-1] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=testConfig, profiles=[test], label=master, version=1a3c751881fafba65375442cec951383f30d4cb9, state=null
2017-07-30 09:09:12.621  INFO 30953 --- [nio-7002-exec-1] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='configClient'], MapPropertySource [name='https://github.com/mdxdjh/spring_cloud/cloud-config-repo/testConfig-test.properties']]]
2017-07-30 09:09:12.627  INFO 30953 --- [nio-7002-exec-1] o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
2017-07-30 09:09:12.629  INFO 30953 --- [nio-7002-exec-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@680af19f: startup date [Sun Jul 30 09:09:12 HKT 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@2bc3bf56
2017-07-30 09:09:12.632  INFO 30953 --- [nio-7002-exec-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2017-07-30 09:09:12.648  INFO 30953 --- [nio-7002-exec-1] o.s.boot.SpringApplication               : Started application in 6.485 seconds (JVM running for 190.678)
2017-07-30 09:09:12.649  INFO 30953 --- [nio-7002-exec-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@680af19f: startup date [Sun Jul 30 09:09:12 HKT 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@2bc3bf56
2017-07-30 09:09:12.650  INFO 30953 --- [nio-7002-exec-1] c.n.e.EurekaDiscoveryClientConfiguration : Unregistering application testConfig with eureka with status DOWN
2017-07-30 09:09:12.650  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
2017-07-30 09:09:12.656  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClient
2017-07-30 09:09:13.283  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Shutting down DiscoveryClient ...
2017-07-30 09:09:13.283  INFO 30953 --- [nio-7002-exec-1] o.s.c.n.eureka.InstanceInfoFactory       : Setting initial instance status as: STARTING
2017-07-30 09:09:13.284  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Unregistering ...
2017-07-30 09:09:13.289  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_TESTCONFIG/192.168.3.3:testConfig:7002 - deregister  status: 200
2017-07-30 09:09:13.295  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Completed shut down of DiscoveryClient
2017-07-30 09:09:13.295  INFO 30953 --- [nio-7002-exec-1] c.n.e.EurekaDiscoveryClientConfiguration : Unregistering application testConfig with eureka with status DOWN
2017-07-30 09:09:13.298  INFO 30953 --- [nio-7002-exec-1] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON encoding codec LegacyJacksonJson
2017-07-30 09:09:13.298  INFO 30953 --- [nio-7002-exec-1] c.n.d.provider.DiscoveryJerseyProvider   : Using JSON decoding codec LegacyJacksonJson
2017-07-30 09:09:13.299  INFO 30953 --- [nio-7002-exec-1] c.n.d.provider.DiscoveryJerseyProvider   : Using XML encoding codec XStreamXml
2017-07-30 09:09:13.299  INFO 30953 --- [nio-7002-exec-1] c.n.d.provider.DiscoveryJerseyProvider   : Using XML decoding codec XStreamXml
2017-07-30 09:09:13.361  INFO 30953 --- [nio-7002-exec-1] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration
2017-07-30 09:09:13.362  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Disable delta property : false
2017-07-30 09:09:13.362  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Single vip registry refresh property : null
2017-07-30 09:09:13.362  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Force full registry fetch : false
2017-07-30 09:09:13.362  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Application is null : false
2017-07-30 09:09:13.362  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Registered Applications size is zero : true
2017-07-30 09:09:13.362  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Application version is -1: true
2017-07-30 09:09:13.362  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Getting all instance registry info from the eureka server
2017-07-30 09:09:13.366  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : The response status is 200
2017-07-30 09:09:13.367  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Starting heartbeat executor: renew interval is: 30
2017-07-30 09:09:13.368  INFO 30953 --- [nio-7002-exec-1] c.n.discovery.InstanceInfoReplicator     : InstanceInfoReplicator onDemand update allowed rate per min is 4
2017-07-30 09:09:13.368  INFO 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Discovery Client initialized at timestamp 1501376953368 with initial instances count: 3
2017-07-30 09:09:13.370  INFO 30953 --- [nio-7002-exec-1] c.n.e.EurekaDiscoveryClientConfiguration : Registering application testConfig with eureka with status UP
2017-07-30 09:09:13.370  WARN 30953 --- [nio-7002-exec-1] com.netflix.discovery.DiscoveryClient    : Saw local status change event StatusChangeEvent [timestamp=1501376953370, current=UP, previous=DOWN]
2017-07-30 09:09:13.371  INFO 30953 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_TESTCONFIG/192.168.3.3:testConfig:7002: registering service...
2017-07-30 09:09:13.372  INFO 30953 --- [nio-7002-exec-1] c.n.e.EurekaDiscoveryClientConfiguration : Unregistering application testConfig with eureka with status DOWN
2017-07-30 09:09:13.373  INFO 30953 --- [nio-7002-exec-1] c.n.e.EurekaDiscoveryClientConfiguration : Registering application testConfig with eureka with status UP
2017-07-30 09:09:13.373  INFO 30953 --- [nio-7002-exec-1] c.n.e.EurekaDiscoveryClientConfiguration : Unregistering application testConfig with eureka with status DOWN
2017-07-30 09:09:13.373  INFO 30953 --- [nio-7002-exec-1] c.n.e.EurekaDiscoveryClientConfiguration : Registering application testConfig with eureka with status UP
2017-07-30 09:09:13.374  INFO 30953 --- [nio-7002-exec-1] o.s.cloud.bus.event.RefreshListener      : Received remote refresh request. Keys refreshed []
2017-07-30 09:09:13.378  INFO 30953 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_TESTCONFIG/192.168.3.3:testConfig:7002 - registration status: 204

客户度2:

bootstrap.properties配置

spring.application.name=testConfig
server.port=7003

eureka.client.serviceUrl.defaultZone=http://localhost:7070/eureka/

spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server
spring.cloud.config.profile=test

spring.cloud.config.failFast=true

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

management.security.enabled=false
spring.cloud.bus.trace.enabled=true

pom.xml

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>
阅读 14.1k
4 个回答

找到原因了,在进行判断是否需要同步更新配置的ServiceMatcher类中,isForSelf返回false了,导致没有通知相应的节点去更新配置,但是有个地方没明白,我自己测试this.matcher.match(“*”,“testConfig:7002”)是返回true的,这里却返回false。

this.getServiceId()=testConfig:7002
destinationService=“*”
public boolean isForSelf(RemoteApplicationEvent event) {
        String destinationService = event.getDestinationService();
        return destinationService == null || destinationService.trim().isEmpty() || this.matcher.match(destinationService, this.getServiceId());
}

将请求的post改成:curl -X POST http://localhost:7003//bus/re... -d 'destination=**'既可

我的client也不被更新,已经http://localhost:8888/bus/refresh?destination=** 这样刷新了

在spring boot2版本,spring cloud F版本,集成spring-cloud-starter-bus-amqp。调用bus-refresh语句发生变化。

//直接更新某个应用(config-client)post
//http://localhost:6003/actuator/refresh     


//总线类型更新(config-server)   更新全部
//http://localhost:6001/actuator/bus-refresh    


//通过总线更新某个应用  post
//http://localhost:6001/actuator/bus-refresh/eureka-client:6007   

//更新eureka-client应用全部实例  post
//http://localhost:6001/actuator/bus-refresh/eureka-client:*     
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题