简体   繁体   English

Spring Cloud Config + Spring Cloud Bus + RabbitMQ-无法使用本地Git存储库自动刷新客户端

[英]Spring Cloud Config + Spring Cloud Bus + RabbitMQ - Not auto refreshing clients with local Git repository

I have some applications getting its configuration from a Spring Cloud Config Server ( Brixton.RELEASE ) and would like to enable the auto refresh of its properties. 我有一些应用程序从Spring Cloud Config Server( Brixton.RELEASE )获取其配置,并希望启用其属性的自动刷新。 I have followed Spring Cloud Config documentation to configure both the server and client apps but, when making changes on the local git files nothing happens. 我已经按照Spring Cloud Config 文档来配置服务器和客户端应用程序,但是,在本地git文件上进行更改时,什么也没有发生。

the default configuration also detects filesystem changes in local git repositories (the webhook is not used in that case but as soon as you edit a config file a refresh will be broadcast). 默认配置还可以检测本地git存储库中的文件系统更改(在这种情况下不使用webhook,但是一旦您编辑配置文件,就会广播刷新)。

Can anybody point out what could be wrong or where to debug in Spring Cloud's code to check it? 谁能指出什么是错误的,或者在Spring Cloud的代码中进行调试以进行检查?

Spring cloud Server Config : Spring Cloud Server Config

server:
  port: 8888

info:
  description: Spring Cloud Config Server

spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          uri: file:///C:/Users/myuser/git/config-dev/

Spring Cloud Server pom.xml Spring Cloud Server pom.xml

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

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

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-monitor</artifactId>
    </dependency>

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>

Spring Cloud Config Startup logs : Spring Cloud Config启动日志

o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel springCloudBusInput
o.s.i.monitor.IntegrationMBeanExporter   : Located managed bean 'org.springframework.integration:type=MessageChannel,name=springCloudBusInput': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=springCloudBusInput]
o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel springCloudBusOutput
o.s.i.monitor.IntegrationMBeanExporter   : Located managed bean 'org.springframework.integration:type=MessageChannel,name=springCloudBusOutput': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=springCloudBusOutput]
o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel errorChannel
o.s.i.monitor.IntegrationMBeanExporter   : Located managed bean 'org.springframework.integration:type=MessageChannel,name=errorChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=errorChannel]
o.s.i.monitor.IntegrationMBeanExporter   : Registering MessageChannel nullChannel
o.s.i.monitor.IntegrationMBeanExporter   : Located managed bean 'org.springframework.integration:type=MessageChannel,name=nullChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=nullChannel]
o.s.i.monitor.IntegrationMBeanExporter   : Located managed bean 'org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal': registering with JMX server as MBean [org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal]
o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase -2147482648
o.s.c.s.binding.BindableProxyFactory     : Binding outputs for :interface org.springframework.cloud.bus.SpringCloudBusClient
o.s.c.s.binding.BindableProxyFactory     : Binding :interface org.springframework.cloud.bus.SpringCloudBusClient:springCloudBusOutput
s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@707ca986: startup date [Fri May 13 10:03:10 CEST 2016]; root of context hierarchy
trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$73faa1d3] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
o.s.cloud.commons.util.InetUtils         : Cannot determine local hostname
e.m.a.config.ConfigServerApplication     : No active profile set, falling back to default profiles: default
s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1ca610a0: startup date [Fri May 13 10:03:11 CEST 2016]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@294a6b8e
o.s.c.support.GenericApplicationContext  : Refreshing org.springframework.context.support.GenericApplicationContext@6048e26a: startup date [Fri May 13 10:03:11 CEST 2016]; root of context hierarchy
e.m.a.config.ConfigServerApplication     : Started ConfigServerApplication in 2.907 seconds (JVM running for 12.366)
o.s.a.r.c.CachingConnectionFactory       : Created new connection: SimpleConnection@7bbcf6f0 [delegate=amqp://guest@127.0.0.1:5672/]
o.s.i.endpoint.EventDrivenConsumer       : Adding {message-handler:outbound.springCloudBus} as a subscriber to the 'springCloudBusOutput' channel
o.s.integration.channel.DirectChannel    : Channel 'config-server:8888.springCloudBusOutput' has 1 subscriber(s).
o.s.i.endpoint.EventDrivenConsumer       : started outbound.springCloudBus
o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase -2147482648
o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
o.s.i.channel.PublishSubscribeChannel    : Channel 'config-server:8888.errorChannel' has 1 subscriber(s).
o.s.i.endpoint.EventDrivenConsumer       : started _org.springframework.integration.errorLogger
o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 2147482647
o.s.c.s.binding.BindableProxyFactory     : Binding inputs for :interface org.springframework.cloud.bus.SpringCloudBusClient
o.s.c.s.binding.BindableProxyFactory     : Binding :interface org.springframework.cloud.bus.SpringCloudBusClient:springCloudBusInput
o.s.c.s.b.r.RabbitMessageChannelBinder   : declaring queue for inbound: springCloudBus.anonymous.t4cuHSE6RfKRYvPvrgfbUg, bound to: springCloudBus
o.s.integration.channel.DirectChannel    : Channel 'springCloudBus.anonymous.t4cuHSE6RfKRYvPvrgfbUg.bridge' has 1 subscriber(s).
o.s.i.a.i.AmqpInboundChannelAdapter      : started inbound.springCloudBus.anonymous.t4cuHSE6RfKRYvPvrgfbUg

Client App pom.xml : 客户端应用程序pom.xml

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

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

    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.1.0.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
    </dependency>

Client App config : 客户端应用配置

spring:
  application:
    name: app
  cloud:
    config:
      uri: http://localhost:8888

Client App Startup log : 客户端应用启动日志

o.s.b.a.e.m.EndpointHandlerMapping  INFO - Mapped "{[/bus/refresh],methods=[POST]}" onto public void org.springframework.cloud.bus.endpoint.RefreshBusEndpoint.refresh(java.lang.String)
...
o.s.i.m.IntegrationMBeanExporter  INFO - Registering beans for JMX exposure on startup
o.s.i.m.IntegrationMBeanExporter  INFO - Registering MessageChannel springCloudBusInput
o.s.i.m.IntegrationMBeanExporter  INFO - Located managed bean 'org.springframework.integration:type=MessageChannel,name=springCloudBusInput': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=springCloudBusInput]
o.s.i.m.IntegrationMBeanExporter  INFO - Registering MessageChannel springCloudBusOutput
o.s.i.m.IntegrationMBeanExporter  INFO - Located managed bean 'org.springframework.integration:type=MessageChannel,name=springCloudBusOutput': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=springCloudBusOutput]
o.s.i.m.IntegrationMBeanExporter  INFO - Registering MessageChannel nullChannel
o.s.i.m.IntegrationMBeanExporter  INFO - Located managed bean 'org.springframework.integration:type=MessageChannel,name=nullChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=nullChannel]
o.s.i.m.IntegrationMBeanExporter  INFO - Registering MessageChannel errorChannel
o.s.i.m.IntegrationMBeanExporter  INFO - Located managed bean 'org.springframework.integration:type=MessageChannel,name=errorChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=errorChannel]
o.s.i.m.IntegrationMBeanExporter  INFO - Located managed bean 'org.springframework.integration:type=MessageHandler,name=org.springframework.cloud.bus.BusAutoConfiguration.acceptRemote.serviceActivator,bean=endpoint': registering with JMX server as MBean [org.springframework.integration:type=MessageHandler,name=org.springframework.cloud.bus.BusAutoConfiguration.acceptRemote.serviceActivator,bean=endpoint]
o.s.i.m.IntegrationMBeanExporter  INFO - Located managed bean 'org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal': registering with JMX server as MBean [org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal]
o.s.b.a.e.j.EndpointMBeanExporter  INFO - Registering beans for JMX exposure on startup

Try to go through this documentation spring-cloud-config-push-notifications and do not forget to install ngrock. 尝试阅读本文档spring-cloud-config-push-notifications ,不要忘记安装ngrock。 Also if you just need to refresh on git commit then you do not even need cloud-bus project just config should be enough. 另外,如果您只需要刷新git commit,那么您甚至不需要cloud-bus项目,只需config就足够了。 Hope this helps. 希望这可以帮助。

You would need a Config server with Spring Cloud Bus and RabbitMQ (or Kafka or Redis) support. 您将需要具有Spring Cloud Bus和RabbitMQ(或Kafka或Redis)支持的Config服务器。

...
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-config-monitor</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
...

RabbitMQ with the following exchange: RabbitMQ与以下交换:

name : springCloudBus 名称 :springCloudBus

type : topic 类型 :主题

durable : true 耐用 :正确

autoDelete : false autoDelete :假

internal : false 内部 :假

The Config server would send data to the topic once it receives push events from any of Github, Bitbucket or GitLab, via a webhook to http://<config-server>/monitor 一旦Config服务器从Github,Bitbucket或GitLab中的任何一个接收到推送事件,就会通过Webhook到http:// <config-server> / monitor发送数据到主题。

And a client application with Config and RabbitMQ libraries: 以及具有Config和RabbitMQ库的客户端应用程序:

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

Subscribed to the previous exchange to receive messages with the properties that need to be refreshed. 订阅上一个交换以接收具有需要刷新的属性的消息。

More could be found in my blog at: http://tech.asimio.net/2017/02/02/Refreshable-Configuration-using-Spring-Cloud-Config-Server-Spring-Cloud-Bus-RabbitMQ-and-Git.html with a brief explanation of the configuration, logs and full source code for the Config server and client app. 可以在我的博客中找到更多信息: http : //tech.asimio.net/2017/02/02/Refreshable-Configuration-using-Spring-Cloud-Config-Server-Spring-Cloud-Bus-RabbitMQ-and-Git .html以及配置服务器和客户端应用程序的配置,日志以及完整的源代码的简要说明。

You need have fallowing dependent in the pom.xml compile('org.springframework.cloud:spring-cloud-stream-binder-rabbit') - Gradle if you have hosed you rabbitmq in the another system you need to specify the host file in the application.properties 您需要在pom.xml编译中具有休闲依存关系('org.springframework.cloud:spring-cloud-stream-binder-rabbit')-如果在另一个系统中用Rabbitmq进行了软管缓冲,则需要在其中指定宿主文件application.properties

spring.rabbitmq.host: {{hostname}} spring.rabbitmq.host:{{hostname}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM