SpringBoot以Java Config方式配置RabbitMQ生产环境队列

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/t1g2q3/article/details/84893502
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class QueueConfig {


    @Value("${exchange}")
    private String exchange;

    @Bean
    DirectExchange exchangeFactory() {
        return new DirectExchange(exchange);
    }

    @Value("${queue}")
    private String queneNameA;

    @Value("${routingkey}")
    private String routingkeyA;

    @Bean(name = "queueA")
    public Queue queueFactoryA() {
        // 查看源码 默认创建持久化的队列
        return new Queue(queueNameA);
    }

    @Bean
    Binding bindingQueueA(@Qualifier("queueA") Queue queue, DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with(routingkeyA);
    }

}

猜你喜欢

转载自blog.csdn.net/t1g2q3/article/details/84893502