简体   繁体   中英

Spring Cloud Config Client connecting to RabbitMQ

I have been trying to set up a Spring Cloud Config Server/Client. I have been following a few different examples ( 1 , 2 ). I have the client and server set up correctly and can successfully query localhost:8888/localhost:8080 to see the values in JSON format.

My question is whether Spring Boot will automatically detect these properties provided by 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. It does not connect to Rabbit or create the queues/exchanges.

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.

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.

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. 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. Its well described here: 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:

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

to your bootstrap.yml file ( its same as application.yml, just loaded earlier ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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