RabbitMQ direct交换器

1:队列和交换器多次绑定

String[] routekeys={"routekey1","routekey2","routekey3"};

for(String routekey:routekeys){
  channel.queueBind(queueName,DirectProducer.EXCHANGE_NAME,routekey);
}

当发送者发送routekey1、routekey2、routekey3的路由键时,会匹配到这个消费者当中。

2:一个连接,连接到多个信道

/*创建一个信道*/

Channel channel1 = connection.createChannel();

Channel channel2 = connection.createChannel();

当消费者创建多个信道,每个信道都连接相同的交换器、队列、路由键(routekey)。

相同的路由键,会匹配到不同的队列当中。

3:一个队列多个消费者

channel.queueBind(queueName,DirectProducer.EXCHANGE_NAME,routekey);

不同的消费者,创建相同的队列,绑定相同的交换器,绑定相同的key。

MQ会使用轮训的方式,发送到不同的消费者当中。

原文地址:https://www.cnblogs.com/orange-time/p/11632001.html