Spring RabbitTemplate - How to create queues automatically upon send

后端 未结 2 359
刺人心
刺人心 2021-01-18 03:15

I am using RabbitMQ together with Spring\'s RabbitTemplate.

When sending messages to queues using the template send methods, I want the queue to automatically be cre

2条回答
  •  遥遥无期
    2021-01-18 04:13

    You can use a RabbitAdmin to automatically declare the exchange, queue, and binding. Check out this thread for more detail. This forum also bit related to your scenario. I have not tried spring with AMQP though, but I believe this would do it.

    /**
     * Required for executing adminstration functions against an AMQP Broker
     */
    @Bean
    public AmqpAdmin amqpAdmin() {
        return new RabbitAdmin(connectionFactory());
    }
    

    Keep coding !

提交回复
热议问题