本文整理汇总了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()