简体   繁体   English

连接到OpenStack中的RabbitMQ代理

[英]Connect to RabbitMQ broker in OpenStack

OpenStack uses RabbitMQ as a messaging system. OpenStack使用RabbitMQ作为消息传递系统。 There are several exchanges and queues for this purpose. 为此有多个交换和队列。 I found that exchange named "nova" of type "topic" used for message transfer. 我发现交换类型为“ topic”的名为“ nova”的交换用于消息传输。 Exchange use routing key to route message to queues ( http://www.rabbitmq.com/tutorials/amqp-concepts.html ). Exchange使用路由键将邮件路由到队列( http://www.rabbitmq.com/tutorials/amqp-concepts.html )。 (Useful image at http://www.rabbitmq.com/img/tutorials/intro/hello-world-example-routing.png - not enough reputation to post it here) There are several queues in OpenStack like compute, cert, network and so on. (位于http://www.rabbitmq.com/img/tutorials/intro/hello-world-example-routing.png的有用图像-信誉不足,无法在此处发布) OpenStack中有多个队列,例如计算,证书,网络等等。 They use routing key with the same name. 他们使用具有相同名称的路由密钥。 So I created several new queues with these routing keys to bind them with consumer that handle messages. 因此,我使用这些路由键创建了几个新队列,以将它们与处理消息的使用者绑定在一起。 For example, there is queue named "compute" that use routing key named "compute". 例如,存在一个名为“计算”的队列,该队列使用名为“计算”的路由键。 I created new queue "my_compute" that use same routing key. 我创建了使用相同路由键的新队列“ my_compute”。 As I think it should work and I will get messages. 正如我认为的那样,我会收到消息。

I have some code that connects to exchange, creates my queues and the consumer. 我有一些连接交流的代码,创建了队列和使用者。

def connect(params):
connection = kombu.Connection(hostname=params['host'])
exchange = kombu.entity.Exchange(name=params['exchange_name'],
                                 type=params['exchange_type'],
                                 durable=params['exchange_durable'],
                                 auto_delete=params['exchange_auto_delete'],
                                 internal=params['exchange_internal'])
queue_list = []
for queue in params['queues_params']:
queue_list.append(kombu.messaging.Queue(name=queue['name'],
                                        exchange=exchange,
                                        routing_key=queue['routing_key'],
                                        channel=connection.channel(),
                                        durable=queue['durable'],
                                        auto_delete=queue['auto_delete']))
consumer = kombu.messaging.Consumer(channel=connection.channel(),
                                    queues=queue_list, 
                                    no_ack=True,
                                    callbacks=[self._process_message])
consumer.consume()
return connection

Argument "params" is the map that got from json file: 参数“ params”是从json文件获取的地图:

{
"host"                 : "xxx",
"exchange_name"        : "nova",
"exchange_type"        : "topic",
"exchange_durable"     : false,
"exchange_auto_delete" : false,
"exchange_internal"    : false,
"queues_params"        : [
    {
        "name"        : "my_compute",
        "routing_key" : "compute",
        "durable"     : false,
        "auto_delete" : false,
        "arguments"   : [ ]
    },
    {
        "name"        : "my_network",
        "routing_key" : "network",
        "durable"     : false,
        "auto_delete" : false,
        "arguments"   : [ ]
    },
    .
    .
    .

It's working. 工作正常 But I only get messages for network queue . 但是我只收到网络队列的消息。 I don't know are there any other messages, but it looks like there are. 我不知道还有其他消息,但看起来好像还有。 Am I right? 我对吗? Or something is wrong? 还是出了什么问题? Is there other messages and how can I get them? 还有其他消息,我该如何获取?

This code is undergoing some active changes in this development cycle, but at the moment I'd assert you're looking a bit deeply. 该代码在此开发周期中正在进行一些积极的更改,但此刻我断言您正在深入研究。 For most of the nova components, the queue interfaces are abstracted away underneath the RPC common library that those components use, and that chooses the topics and queues. 对于大多数nova组件,队列接口是在这些组件使用的RPC公共库下抽象出来的,该库选择主题和队列。

In particular, topics can also be host specific when the RPC code wants to send a message to a specific compute, network, or storage host. 特别是,当RPC代码希望将消息发送到特定的计算,网络或存储主机时,主题也可以是特定于主机的。 The only messages you'll be seeing above are the general broadcast messages, which in practice will often be requests for information about floating IP addresse 您在上面看到的唯一消息是常规广播消息,实际上,通常是对浮动IP地址信息的请求。

If you want an example of something that snags all the messages on the queue, you should definitely look at Ceilometer, which is intended to do just that, and leverages the notification system that's also embedded into nova and related components. 如果您想要一个示例,将所有消息都塞入队列,则绝对应该查看Ceilometer,它旨在实现这一目的,并利用也嵌入在nova和相关组件中的通知系统。 It's not going to offer you the same thing that intercepting and interpretting nova, network, and cinder messages would - just sort of depends on your overall goals if that's useful. 它不会像拦截和解释新星,网络和煤渣消息那样为您提供相同的东西-如果有用的话,这取决于您的总体目标。

In the routing_key in your queues_params, you have specified "network" that is why you are receiving only network messages. 在queues_params中的routing_key中,您指定了“ network”,这就是为什么仅接收网络消息的原因。 You can use the wildcard routing_key "#" which captures all message associated with the corresponding topic exchange. 您可以使用通配符routing_key“#”捕获与相应主题交换关联的所有消息。 You can see my note for this if you will. 如果可以的话,您可以看到我的备忘

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM