OpenStack 环境中rabbitmq server 创建Exchange,Queue 总结

Server端会创建三种类型的consumer,如下所示:


conn.declare_topic_consumer(exchange_name=self._get_exchange(target),
                                    topic=target.topic,
                                    callback=listener)
conn.declare_topic_consumer(exchange_name=self._get_exchange(target),
                                    topic='%s.%s' % (target.topic,
                                                     target.server),
                                    callback=listener)
conn.declare_fanout_consumer(target.topic, listener)

若以neutron为例,执行exchange_name=self._get_exchange(target),exchange的值为neutron,配置文件中的默认值就是neutron。

上述三行代码中,创建了两种类型的exhange,下面会进行说明:

假设tpoic 名称为topic1

1、toptic类型的exchange

  exchange名称:neutron 。topic有两种,分别为topic1, topic1.controller。

       Queue名称分别为自己的topic名称  。

      

    def declare_topic_consumer(self, exchange_name, topic, callback=None,
                               queue_name=None):
        """Create a 'topic' consumer."""
        consumer = Consumer(exchange_name=exchange_name,
                            queue_name=queue_name or topic,
                            routing_key=topic,
                            type='topic',
                            durable=self.amqp_durable_queues,
                            exchange_auto_delete=self.amqp_auto_delete,
                            queue_auto_delete=self.amqp_auto_delete,
                            callback=callback,
                            rabbit_ha_queues=self.rabbit_ha_queues)

        self.declare_consumer(consumer)

2、fauot类型的exchange

        通过代码可以发现,fanout的exchange 名称为'%s_fanout' % topic,即为topic1_fanout

  Queue名称为topic1_fanout_unique(uniqe为字符串名称)

class FanoutConsumer(ConsumerBase):
    def __init__(self, conf, channel, topic, callback, tag, **kwargs):
        
        unique = uuid.uuid4().hex
        exchange_name = '%s_fanout' % topic
        queue_name = '%s_fanout_%s' % (topic, unique)
     #队列名称

下表是rabbitmq队列():

OverviewMessagesMessage rates
NameFeaturesStateReadyUnackedTotalincomingdeliver / getack
topic1-compute idle0000.00/s0.00/s0.00/s
topic1-compute.compute idle000   
topic1-compute_fanout_714085bbdc8b427db85073d207fcefc8Expidle0000.00/s0.00/s0.00/s
topic1-controller idle0000.00/s0.00/s0.00/s
topic1-controller.controller idle000   
topic1-controller_fanout_22c8a35ce1cb41d8af6ef8f08c5299b5Expidle0000.00/s0.00/s0.00/s

 3、不同类型的发送方式会选择不同的exchange

      1)、若发送方式为fanout方式,那么使用由带fanout字样的exchange来处理,和带fanout字样的队列去处理。

      2)、若发送方式中,未使用fanout(fanout=false),那么使用neutron exchange来处理,由topic名称的队列处理消息。

4、查看exchange 和队列的绑定

       rabbitmqctl list_bindings

5、使用rabbit模拟器得出的结论

     1、使用topic 类型的exchange,会把消息,发送所有匹配此topic的消息队列。

     2、若一个队列有多个消费者,用轮循的方式,分别发送消息给每一个消费者。

     3、一个队列出现多个消息者的情况如下:

          前提:生产着发送topic类型的消息,不使用host(server)、fanout=false。

          把一个agent安装到多个节点上,就会出现一个neutron exchange 对应的topic名称的队列上,会多个消费者。

    4、fanout消息

          前提topic一致,agent安装到多个节点上,会出现一个带fanout+topic的exchange,有多个消息队列。

          exchange会忽略生产着的route_key。

6、agent 发送状态报告消息

      这个后面在更新。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值