0

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.

P.S.

Project structure looks like this:

enter image description here

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

1

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;
}
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • If write wrong url - app prints: **Could not refresh JMS Connection for destination 'my_queue_new' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: ololo** – gstackoverflow Aug 21 '17 at 15:14
  • So don't "write" the wrong URL :) What do you expect? – Gary Russell Aug 21 '17 at 15:15
  • All right despite the fact I expected application won't start(could not load bean from context or something like this). I believe developers had arguments to make it so. – gstackoverflow Aug 21 '17 at 15:19
  • That's how spring-jms handles connection problems. – Gary Russell Aug 21 '17 at 15:26
  • As I understand I can replace DefaultMessageListenerContainer with my own implementation of AbstractPollingMessageListenerContainer – gstackoverflow Aug 21 '17 at 15:28
  • You could also provide your own bean that implements `SmartLifecycle` and try to create a connection in the `start()` method; if that throws an exception, the application won't load. – Gary Russell Aug 21 '17 at 15:42