spring 配置服务器未发布到 rabbitmq

spring config server not posting to rabbitmq

我从 spring 的 initialzr 生成了一个 spring 启动配置服务器。

我已经用 brew 安装了 rabbitmq。使用引导版本 2.1.1.RELEASE 和云版本 Greenwich.M3 生成的 initialzr。

简单的休息服务正在连接到 rabbitmq 队列。配置服务器连接到 gitlab 配置仓库。

但是当我提交并向其推送更改时,服务应用程序并未反映该更改。配置服务器在推送完成时获取日志消息。谁能说出什么可能是错的? rabbitmq 控制台中似乎从未出现过任何消息。不过,我已经能够通过 actuator/bus-refresh 通过 rabbitmq 刷新属性。

config-server 将更改提交到 config-repo 的员工-service.yml 文件时的日志消息:

2018-12-07 11:53:12.185  INFO 84202 --- [nio-8888-exec-1] o.s.c.c.monitor.PropertyPathEndpoint     : Refresh for: employee:service
2018-12-07 11:53:12.228  INFO 84202 --- [nio-8888-exec-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$b43cc593] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-12-07 11:53:12.253  INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
2018-12-07 11:53:12.259  INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication               : Started application in 0.072 seconds (JVM running for 3075.606)
2018-12-07 11:53:12.345  INFO 84202 --- [nio-8888-exec-1] o.s.cloud.bus.event.RefreshListener      : Received remote refresh request. Keys refreshed []
2018-12-07 11:53:12.345  INFO 84202 --- [nio-8888-exec-1] o.s.c.c.monitor.PropertyPathEndpoint     : Refresh for: employee-service
2018-12-07 11:53:12.377  INFO 84202 --- [nio-8888-exec-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$b43cc593] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-12-07 11:53:12.398  INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication               : No active profile set, falling back to default profiles: default
2018-12-07 11:53:12.402  INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication               : Started application in 0.056 seconds (JVM running for 3075.749)
2018-12-07 11:53:12.489  INFO 84202 --- [nio-8888-exec-1] o.s.cloud.bus.event.RefreshListener      : Received remote refresh request. Keys refreshed []

config-server 有这个 application.yml:

---

server:
  port: ${PORT:8888}

spring:
  cloud:
    bus:
      enabled: true
    config:
      server:
        git:
          uri: ${CONFIG_REPO_URI:git@gitlab.<somedomain>:<somegroup>/config-repo.git}
          search-paths:
          - feature/initial-repo

  main:
    banner-mode: "off"

和ConfigServerApplication.java:

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

和这些 gradle 依赖项:

dependencies {
    implementation('org.springframework.cloud:spring-cloud-config-server')
    implementation('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
    implementation('org.springframework.cloud:spring-cloud-config-monitor')
    testImplementation('org.springframework.boot:spring-boot-starter-test')
    implementation('org.springframework.cloud:spring-cloud-stream-test-support')
}

服务有这个 applciation.yml:

---
server:
  port: 8092

management:
  security:
    enabled: "false"

  endpoints:
    web:
      exposure:
        include: 
        - '*'

spring:
  main:
    banner-mode: "off"

  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest

这个bootstrap.yml:

---

spring:
  application:
    name: employee-service

  cloud:
    config:
      uri: 
      - http://localhost:8888
      label: feature(_)initial-repo

这些 gradle 依赖项:

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    implementation('org.springframework.cloud:spring-cloud-starter-config')
    implementation('org.springframework.cloud:spring-cloud-starter-bus-amqp')
    implementation('org.springframework.boot:spring-boot-starter-actuator')
    testImplementation('org.springframework.boot:spring-boot-starter-test')
}

这个主要class:

@SpringBootApplication
public class EmployeeServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(EmployeeServiceApplication.class, args);
    }
}

和这个控制器class:

@RefreshScope
@RestController
public class WelcomeController {

    @Value("${app.service-name}")
    private String serviceName;

    @Value("${app.shared.attribute}")
    private String sharedAttribute;

    @GetMapping("/service")
    public String getServiceName() {
        return "service name [" + this.serviceName + "]";
    }

    @GetMapping("/shared")
    public String getSharedAttribute() {
        return " application.yml [" + this.sharedAttribute + "]";
    }
}

尝试使用 Maven 而不是 Gradle 创建和构建项目。

我遇到了同样的问题。我有两个具有相同 RabbitMQ 依赖项的相同应用程序,一个是使用 Maven 构建的,第二个是使用 Gradle 构建的。基于 Maven 的应用程序按预期将内容发布到 RabbitMQ。使用 Gradle 构建的同一个应用程序不会与 RabbitMQ 建立连接,也不会发布事件。 为了进一步澄清,我 运行 Eclipse 中的两个应用程序都带有 Spring 工具。