我想我在使用 RabbitMQ 实现 Spring Cloud Bus 方面陷入了死胡同。
请记住,这是通过Spring Boot 2.0.0.M7 和 Spring Cloud Finchley.M5 完成的,根据它们的发行说明应该是兼容的。
我试图让它发挥作用:
/actuator/bus-refreshPOST 调用接收刷新请求但是,我可以在服务器的日志中看到这一点:
o.s.cloud.bus.event.RefreshListener      : Received remote refresh request. Keys refreshed []
(空数组是罪魁祸首吗?在这种情况下,我真的不知道该怎么办:()
客户端没有任何内容(除非我手动向总线刷新端点发送 POST 请求)......在这种情况下,日志中的输出如下:
o.s.cloud.bus.event.RefreshListener      : Received remote refresh request. Keys refreshed [config.client.version, message]
当我查看 RabbitMQ(作为 Docker 容器运行)中的图表时,我看到了三个连接的应用程序:客户端、Zuul(反向代理)和配置服务器。
你能帮我解决这个问题吗?非常感谢。以下是我对应用程序的配置。
配置服务器 POM.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.paromsoft</groupId>
    <artifactId>config</artifactId>
    <version>0.0.1-SNAPSHOT</version> …java spring-boot spring-cloud spring-cloud-config spring-cloud-bus
它们之间有什么区别?
是springcloud-stream的实例之一springcloud-bus吗?
据我所知,他们都关心 MQ。
这是我的 Spring boot 应用程序中的简单代码:
package com.maxxton.SpringBootHelloWorld;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootHelloWorldApplication {
  public static void main(String[] args) {
    SpringApplication.run(SpringBootHelloWorldApplication.class, args);
  }
}
还有一个 ApplicationListener 类来监听 ApplicationEvent:
package com.maxxton.SpringBootHelloWorld;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
@Component
public class Test implements ApplicationListener {
  @Override
  public void onApplicationEvent(ApplicationEvent event) {
    if (event.getClass().getSimpleName().equals("ApplicationReadyEvent")) {
      System.out.println("-------------------------------------");
      System.out.println(event.getClass().getSimpleName());
      System.out.println("-------------------------------------");
    }
  }
}
build.gradle 包含这些依赖项:
dependencies {
    compile("org.springframework.boot:spring-boot-starter-amqp")
    compile("org.springframework.cloud:spring-cloud-starter-bus-amqp")
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter')
    compile("org.springframework.cloud:spring-cloud-starter")
    compile("org.springframework.cloud:spring-cloud-starter-security")
    compile("org.springframework.cloud:spring-cloud-starter-eureka")
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
现在,当我运行这个 Spring Boot 应用程序时,我看到这个日志打印了两次:
[main] c.m.S.SpringBootHelloWorldApplication : Started …rabbitmq spring-rabbit spring-amqp spring-boot spring-cloud-bus
我的 Spring Cloud Config Client 依赖于spring.cloud.starter.bus.amqp,但它仍然没有启用/bus/refresh endpoint
build.gradle    
compile("org.springframework.cloud:spring-cloud-starter-stream-rabbit:1.1.3.RELEASE")    
compile("org.springframework.cloud:spring-cloud-starter-bus-amqp:1.2.2.RELEASE")
我的配置客户端应用程序中有这些依赖项,但仍然没有启用/bus/refresh, /bus/env.
请让我知道我的客户端应用程序中缺少什么。
笔记:
spring.cloud.bus.refresh.enabled: true
spring.cloud.bus.env.enabled: true
endpoints.spring.cloud.bus.refresh.enabled: true
endpoints.spring.cloud.bus.env.enabled: true
我已尝试在 , 中application.yml或application.properties在 , 使用时设置这些指标BusAutoConfiguration以启用/bus/*端点。
@ConditionalOnProperty(value = "endpoints.spring.cloud.bus.refresh.enabled", matchIfMissing = true)
在我的 Spring Cloud Config Server 应用程序中,我禁用了这些端点,即设置为 false
endpoints.spring.cloud.bus.refresh.enabled: false
endpoints.spring.cloud.bus.env.enabled: false
并观察到在 Spring Boot 启动期间/bus/*没有启用端点。
我已经实现了简单的应用程序来了解客户端的 Spring Cloud 配置。
它只包含 2 个类:
主要的:
@SpringBootApplication
public class ClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
}
和控制器:
@RefreshScope
@RestController
public class ExampleController {
    @Value("${example.message:none}")
    private String message;
    @GetMapping("/message")
    public String getMessage() {
        return this.message;
    }
}
和application.properies文件:
server.port = 8080
# Customize the Pub/Sub Topic to be used as the message bus.
spring.cloud.gcp.project-id=spring-samples-269912
spring.cloud.bus.destination=cloud-bus-demo-topic
spring.cloud.config.uri=http://35.202.199.184
spring.cloud.gcp.credentials.location=file:secret.json
构建.gradle:
buildscript {      // Configuration for building
    repositories {
        jcenter()      // Bintray's …我发现 Spring Cloud Bus在version上不支持对/actuator/bus-refresh 的POST 请求。当我尝试发送它时,我收到 405“方法不允许”。有没有办法在不使用/monitor和 git webhooks 或降级 Spring Cloud 版本的情况下自动刷新所有客户端服务的配置?Spring Cloud2020.0.0
我已经包含了spring-cloud-starter-bus-amqp依赖spring-boot-starter-actuator项,bus-refresh端点已公开。RabbitMQ 已启动并正在运行,在我的服务启动时创建了 springCloudBus 主题并添加了队列。当我向/actuator/bus-refresh发出 GET 请求时,它会将属性源获取到我的配置服务器,但我的客户端服务属性文件不会刷新,消息也不会添加到队列中。
spring-cloud spring-boot-actuator spring-cloud-config spring-cloud-bus