当前位置: 首页>>代码示例>>Python>>正文


Python AMQClient.start方法代码示例

本文整理汇总了Python中txamqp.protocol.AMQClient.start方法的典型用法代码示例。如果您正苦于以下问题:Python AMQClient.start方法的具体用法?Python AMQClient.start怎么用?Python AMQClient.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在txamqp.protocol.AMQClient的用法示例。


在下文中一共展示了AMQClient.start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AMQFactory

# 需要导入模块: from txamqp.protocol import AMQClient [as 别名]
# 或者: from txamqp.protocol.AMQClient import start [as 别名]
class AMQFactory(protocol.ReconnectingClientFactory):
    VHOST = '/'

    def __init__(self, creds):
        self.spec = txamqp.spec.load(SPECFILE)
        self.creds = creds
        self.client = None
        self.channel  = None

    def buildProtocol(self, addr):
        self.resetDelay()
        delegate = TwistedDelegate()
        self.client = AMQClient(delegate=delegate, vhost=self.VHOST, spec=self.spec)
        self.client.start(self.creds)
        return self.client

    @defer.inlineCallbacks
    def publish(self, exchange, msg, routing_key):
        if not self.client:
            raise NotImplementedError
        if not self.channel:
            yield self._createChannel()
        content = Content(msg)
        yield self.channel.basic_publish(exchange=exchange, content=content, routing_key=routing_key)

    @defer.inlineCallbacks
    def _createChannel(self):
        self.channel = yield self.client.channel(1)
        yield self.channel.channel_open()
开发者ID:ivaxer,项目名称:tippresence,代码行数:31,代码来源:publisher.py


注:本文中的txamqp.protocol.AMQClient.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。