个人blog:http://www.sskywatcher.com/blog
由sskywatcher翻译,转载请注明出处
目录
模块nova.notifications.objects.base
概述
与 OpenStack 的其他服务模块类似,Nova 使用 oslo.messaging 模块提供的 Notifier 类 项消息总线发出通知消息。 从一个通知消息的消费者角度来看,一个通知消息(notification) 包含两个部分:一个由 oslo.messaging 定义好的有固定结构格式的消息封皮(envelope )部分、 一个由通知消息的发出者服务定义的负载(payload)。消息封皮的格式如下所示:
{ "priority": <string, selected from a predefined list by the sender>, "event_type": <string, defined by the sender>, "timestamp": <string, the isotime of when the notification emitted>, "publisher_id": <string, defined by the sender>, "message_id": <uuid, generated by oslo>, "payload": <json serialized dict, defined by the sender> }
在本地环境中配置 nova 配置文件的一下部分,可以完全关闭 Notification 功能 :
[oslo_messaging_notifications] driver = noop
Nova 中有两种不同类型的通知 : 负载消息没有版本之分的经典的通知消息、支持多版本负载消息的通知消息。
不支持多版本的经典通知
Nova 的代码使用 nova.rpc.get_notifier 来获取已经配置好的 oslo.messaging Notifier 对象, 使用olso组件提供的Notifier 的成员方法来发送通知。 get_notifier 调用的参数以及 oslo.messaging 模块配置的选项 "driver"
和 "topics"决定了获取到的
Notifier 对象的配置。Nova 中有多个配置选项,这些选项用于指定 notification 的类型,如下例:
notifications.notify_on_state_change
,notifications.default_level
,
等等。
发送通知的代码中定义了无多版本支持的通知的负载的结构,这种格式没有文档记载说明,也不考虑任何的后向兼容性。
支持多版本的新型通知
支持多版本的新型通知资格概念之所以被提出来,就是为了弥补老式通知的缺点。 oslo.messaging 给这种新型通知提供的消息封皮部分的结构与老式通知消息的完全相同。 但是负载部分不再是一个自由定义的字典格式,相应的部分被 olso 的 versionedobjects 模块的对象所取代。
举一个例子:service.update
通知消息的格式如下所示:
{ "priority":"INFO", "payload":{ "nova_object.namespace":"nova", "nova_object.name":"ServiceStatusPayload", "nova_object.version":"1.0", "nova_object.data":{ "host":"host1", "disabled":false, "last_seen_up":null, "binary":"nova-compute", "topic":"compute", "disabled_reason":null, "report_count":1, "fo