Search code examples
spring-bootrabbitmqapplication.properties

Access amqp_URI from spring boot application.properties file


I have amqp_URI like below

amqp://sds:%23%23%45%56%65%56%56%@myserver:5672 

I need access to this server from Spring boot application.properties file. I have tried spring.rabbitmq.addresses property .But no luck.

any heads up would be appreciated


Solution

  • You can use below properties in application.properties -

    spring.rabbitmq.host=
    spring.rabbitmq.virtual-host= <if you are using root (/) remove this property>
    spring.rabbitmq.port=
    spring.rabbitmq.username=
    spring.rabbitmq.password=
    

    To listen a queue (e.g: test-queue) you can use below code -

    @Component
    public class TestConsumer {
        @RabbitListener(queues = 'test-queue')
        public void onMessage(Message message) {
          //TODO
        }
    }