Search code examples
javaspring-bootrabbitmqspring-rabbit

RabbitMQ queue is not created on spring startup


Please help me to solve issues with Spring rabbitmq queue creation. I've searched every stakcoverflow posted questions, but non seems to work.

I am using Spring 2.7.18. My rabbit configuration class:

@Configuration
public class RabbitConfiguration {

    private final RabbitProperties rabbitProperties;

    public RabbitConfiguration(RabbitProperties rabbitProperties) {
        this.rabbitProperties = rabbitProperties;
    }

    @Bean
    public AmqpAdmin amqpAdmin(ConnectionFactory connectionFactory) {
        AmqpAdmin amqpAdmin = new RabbitAdmin(connectionFactory);
        amqpAdmin.declareQueue(createQueue());
        return amqpAdmin;
    }

    @Bean
    public Declarables queues() {
        return new Declarables(createQueue());
    }

    @Bean
    public Queue createQueue() {  
        return new Queue("queueName", true, false, false);
    }

    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        return new RabbitTemplate(connectionFactory);
    }
}

application.properties

spring.rabbitmq.addresses=xxx
spring.rabbitmq.virtual-host=xxx
spring.rabbitmq.username=xxx
spring.rabbitmq.password=xxx
spring.rabbitmq.ssl.enabled=true
spring.rabbitmq.ssl.algorithm=TLSv1.2

I see that my application created connection. If I have queue created via Rabbit admin panel I can send messages to the rabbit. However, then I delete the queue via admin panel it's not created. I am thinking that queue should be created either during app start up or either sending a message to the rabbit. Am I wrong? :( I use service only to send messages via rabbitTemplate.convertAndSend()

Created new connection: rabbitConnectionFactory#373052b5:0/SimpleConnection@8ca3b65 [delegate=amqp://xxx@xxxx:xxx/vhost, localPort= xxxx]

Solution

  • I was using a clean RabbitMQ instalation with my Spring Boot app, where I seted up a topic and a queue to be created.

    i am thinking that queue should be created either during app start up or either sending a message to the rabbit

    The last one happend to me, the resources and the connection data started to show up in the RabbitMQ management page after, and only after I sent the first message. That might be the cause if someone is experiencing something like it.