简体   繁体   中英

Spring-jms. How to customize broker url for rabbitmq?

All examples I read related with activeMq and spring-boot has especial property to change the url of broker:

spring.activemq.broker-url=<SOME_URL>

By default it uses default settings: default url and default port.
But I use rabbirMq and I want to know how to change broker url

I've read this one

I've added application.properties to the src/main/resources with following content(host absolutely wrong, I expected to see error):

spring.rabbitmq.host=olololo
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest

But it doesn't affect application. Looks like spring(boot) doesn't read these prioerties.

PS

Project structure looks like this:

在此处输入图片说明

Spring Boot does not have auto configuration support for rabbitmq-jms (the link you referenced is the native RabbitMQ AMQP auto configuration).

For the JMS connection factory, you will have to do the configuration yourself...

@Bean
public RMQConnectionFactory connectionFactory(@Value("${spring.rabbitmq.host}") String host,
        @Value("${spring.rabbitmq.port}") int port) {
    RMQConnectionFactory cf = new RMQConnectionFactory();
    cf.setHost(host);
    cf.setPort(port);
    return cf;
}

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