oops amqp传输。
oops_amqp的Python项目详细描述
Copyright (c) 2011, Canonical Ltd
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 3 only.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. GNU Lesser General Public License version 3 (see the file LICENSE).
oops_amqp包提供amqp oopshttp://pypi.python.org/pypi/oops) publisher和一个监听amqp上oops报告和 重新发布(到提供的发布服务器)。oops框架允许 如果amqp下跌,则会退回到其他发行商。
依赖关系
- Python2.6+
- bson
- oops(http://pypi.python.org/pypi/oops)0.0.11或更新版本。
- AMQP
测试依赖项
用法
发布到AMQP
在创建oops报告的位置,配置oops_amqp.publisher。这需要 一个连接工厂-一个创建AMQP的简单可调用的 连接-以及要提交到的Exchange名称和路由密钥。
>>> factory = partial(amqp.Connection, host="localhost:5672", ... userid="guest", password="guest", virtual_host="/") >>> publisher = oops_amqp.Publisher(factory, "oopses", "")
将发布服务器提供给您的oops配置:
>>> config = oops.Config() >>> config.publisher = publisher
通过该配置发布的任何oop现在都将通过amqp发送。
oops id是通过散列oops消息(不带id字段)生成的- 这确保了唯一的id。
使用工厂的原因是因为amqp不是线程安全的- publisher维护一个thread locals对象来保存工厂并创建 创建新线程时的连接(当它们第一次生成oops时)。
处理停机时间
您的AMQP服务器可能不可用。如果那样的话 发布服务器将不分配oops id-它将不返回任何以表示 发布失败。为了防止丢失oops,最好有一个 回退发布服务器-其他AMQP发布服务器(到其他服务器)或 一个在本地进行假脱机(在这里您可以通过rsync或一些 其他机制。使用oops标准助手publish_with_fallback将 将回退发布服务器包装起来,以便只有在主发布服务器 方法失败:
>>> fallback_factory = partial(amqp.Connection, host="otherserver:5672", ... userid="guest", password="guest", virtual_host="/") >>> fallback_publisher = oops_amqp.Publisher(fallback_factory, "oopses", "") >>> config.publisher = publish_with_fallback(publisher, fallback_publisher)
从AMQP接收
有一个简单的方法可以运行无限循环来处理来自 AMQP公司要使用它,您需要配置一个本地配置来发布接收到的 报告。使用完整配置,因为它包括对筛选的支持 (例如,如果需要限制音量,这可能很有用)。 此外,您还需要一个amqp连接工厂(以处理amqp服务器 正在重新启动)和要接收的队列名称。
本例使用datedirrepo发布者,告诉它接受 ID由发布到AMQP的进程分配:
>>> publisher = oops_datedir_repo.DateDirRepo('.', inherit_id=True) >>> config = oops.Config() >>> config.publisher = publisher.publish >>> receiver = oops_amqp.Receiver(config, factory, "my queue") >>> receiver.run_forever()
有关更多信息,请参阅pydoc oops_amqp。
安装
在具有所有可用依赖项的环境中运行setup.py,或者 将工作目录添加到pythonpath。
开发
上游开发发生在https://launchpad.net/python-oops-amqp。 如果依赖项不是 立即可用,您可以使用./bootstrap.py创建bin/buildout,然后 bin/py以获得具有可用依赖项的python解释器。
要使用您选择的运行程序运行测试,测试套件是 oops_amqp.tests.tests_套件。
例如:
$ bin/py -m testtools.run oops_amqp.tests.test_suite
如果您有testrepository,您可以使用它运行测试:
$ testr run