简体   繁体   English

Spring Cloud Config Client连接到RabbitMQ

[英]Spring Cloud Config Client connecting to RabbitMQ

I have been trying to set up a Spring Cloud Config Server/Client. 我一直在尝试设置Spring Cloud Config Server / Client。 I have been following a few different examples ( 1 , 2 ). 我已经以下几个不同的实施例( 12 )。 I have the client and server set up correctly and can successfully query localhost:8888/localhost:8080 to see the values in JSON format. 我已经正确设置了客户端和服务器,并且可以成功查询localhost:8888 / localhost:8080以查看JSON格式的值。

My question is whether Spring Boot will automatically detect these properties provided by Spring Cloud Config Server. 我的问题是Spring Boot是否会自动检测Spring Cloud Config Server提供的这些属性。 For now I am just attempting to connect to a RabbitMQ instance on startup but have had no success despite not having any errors. 现在,我只是尝试在启动时连接到RabbitMQ实例,但是尽管没有任何错误,却没有成功。 It does not connect to Rabbit or create the queues/exchanges. 它不会连接到Rabbit或创建队列/交换。

It works when I have an application.properties file locally with the following properties but I wish to get these setting through Spring Cloud Config from a GitHub repository. 当我在本地具有以下属性的application.properties文件时,它可以工作,但我希望通过GitHub存储库中的Spring Cloud Config获得这些设置。

spring.rabbitmq.host=178.61.47.---
spring.rabbitmq.port=5672
spring.rabbitmq.username=mqtt
spring.rabbitmq.password=mqtt

I have looked through the questions here/issues on GitHub but can't see anything relating to this. 我在GitHub上的这里/问题中浏览了问题,但是看不到与此相关的任何内容。

Code for client class is below: 客户端类的代码如下:

@EnableAutoConfiguration
@ComponentScan
@SpringBootApplication
public class ConfigRabbitApplication {

    final static String queueName = "arduino-weather-queue";

    @Autowired
    RabbitTemplate rabbitTemplate;

    @Bean
    Queue queue() {
        return new Queue(queueName, true);
    }

    @Bean
    Binding binding(Queue queue, TopicExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("arduino-weather");
    }

    @Bean
    TopicExchange exchange() {
        return new TopicExchange("arduino-iot-exchange", true, false);
    }

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

}

No, spring boot client is not aware that you want to fetch configuration from config-server. 不,Spring Boot客户端不知道您要从config-server获取配置。 That is probably loaded when specific class in on a classpath, thats why you have to add org.springframework.cloud:spring-cloud-starter-config dependency. 当特定的类放在类路径中时,可能会加载该类,这就是为什么必须添加org.springframework.cloud:spring-cloud-starter-config依赖项的原因。 Its well described here: http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_client_side_usage 其详细描述如下: http : //cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_client_side_usage

In case config-server is not on localhost:8888 you will also have to add: 如果config-server不在localhost:8888上,则还必须添加:

spring.cloud.config.uri: http://myconfigserver.com

to your bootstrap.yml file ( its same as application.yml, just loaded earlier ). 到bootstrap.yml文件(与application.yml相同,之前已加载)。

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

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