有没有用腊味芹菜?

2024-04-24 20:58:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望我把这个贴在正确的地方。在

我正在研究RabbitMQ,以便在我们的Plone网站上使用。我们目前在Plone服务器中的一个专用的worker客户机上进行异步,但是我们正在考虑构建一个专用的RabbitMQ服务器来处理所有Plone消息传递和其他活动。在

我的具体问题是,在Plone中使用芹菜与RabbitMQ相比有什么优势?我找到了用于芹菜集成的this plone add-on,但不确定这是否是最佳路线。我注意到芹菜有花工具来监视排队的人,这将是一个巨大的优势。在

作为一个附带的问题,如果您有兴趣的话,有没有人有任何提示或参考资料来集成RabbitMQ和Plone来处理所有这些请求?我一直在做研究,并得到了RabbitMQ的一般要点,但我似乎无法将Plone活动(例如内容规则和PloneFormGen提交)联系起来。到目前为止,我看到了我要安装的this add-on,看看我能不能弄明白,但我只是想得到一些指导,如果可以的话。在

谢谢你的时间!在


Tags: 服务器add客户机网站onplone地方rabbitmq
1条回答
网友
1楼 · 发布于 2024-04-24 20:58:35

首先,问问你自己,如果你需要RabbitMQ的特性,还是只想用Plone在Python中执行一些异步任务。在

如果您真的不需要RabbitMQ,您可以参考David Glick的gist,了解如何将芹菜与Plone集成(并且仍然将RabbitMQ用于芹菜):

您还可以研究collective.taskqueue(没有芹菜和RabbitMQ的简单队列),但是它还没有提供任何监视解决方案。在

如果你真的需要RabbitMQ,不要吃芹菜,试试collective.zamqp。Celery试图自己充当代理,这会阻止您使用AMQP和RabbitMQ的大多数内置功能。在

RabbitMQ附带了很好的用于监控的web管理插件,还有用于第三方监控系统(比如Zenoss)的插件。在

很抱歉,collective.zamqp仍然缺少叙述性文档,但是您可以查看collective.zamqpdemo中有关其配置和使用的各种示例。在

简而言之,c.zamqp允许您根据生产者和消费者定义配置代理的使用:

from five import grok
from zope.interface import Interface
from collective.zamqp.producer import Producer
from collective.zamqp.consumer import Consumer


class CreateItemProducer(Producer):
    """Produces item creation requests"""
    grok.name("amqpdemo.create")  # is also used as default routing key

    connection_id = "superuser"
    serializer = "msgpack"
    queue = "amqpdemo.create"

    durable = False


class ICreateItemMessage(Interface):
    """Marker interface for item creation message"""


class CreateItemConsumer(Consumer):
    """Consumes item creation messages"""
    grok.name("amqpdemo.create")  # is also used as the queue name

    connection_id = "superuser"
    marker = ICreateItemMessage

    durable = False

通过事务绑定生产者发布消息(仅在事务成功后发布消息):

^{pr2}$

并在熟悉的内容事件处理程序环境中使用消息:

from zope.component.hooks import getSite
from collective.zamqp.interfaces import IMessageArrivedEvent
from plone.dexterity.utils import createContentInContainer

@grok.subscribe(ICreateItemMessage, IMessageArrivedEvent)
def createItem(message, event):
    """Consume item creation message"""

    portal = getSite()
    obj = createContentInContainer(
        portal, "Document", checkConstraints=True, **message.body)

    message.ack()

最后,它将代理连接配置与代码分离,实际的连接参数可以在中定义构建.cfg(允许使用所需数量的实例):

[instance]
recipe = plone.recipe.zope2instance
...
zope-conf-additional =
    %import collective.zamqp
    <amqp-broker-connection>
         connection_id superuser
         heartbeat 120
# These are defaults, but can be defined when required:     
#        hostname localhost
#        virtual_host /
#        username guest
#        password guest
    </amqp-broker-connection>
    <amqp-consuming-server>
        connection_id superuser
        site_id Plone
        user_id admin
        vhm_method_prefix /VirtualHostBase/https/example.com:443/Plone/VirtualHostRoot
    </amqp-consuming-server>

不能从RestrictedPython直接调用c.zamqp,因此将其集成到PloneFormGen需要一个自定义操作适配器或一个从PFG的Python脚本适配器调用的自定义外部方法。在

相关问题 更多 >