本文整理汇总了Python中txamqp.protocol.AMQClient类的典型用法代码示例。如果您正苦于以下问题:Python AMQClient类的具体用法?Python AMQClient怎么用?Python AMQClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AMQClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *args, **kwargs):
print 'init protocol'
self._stop = False
# callback on authenticated
self._auth_succ = Deferred()
# callback on read_channel opened
self._read_opened = Deferred()
# callback on write_channel opened
self._write_opened = Deferred()
# callback on read_loop started
self._read_loop_started = Deferred()
# callback on shutdown read loop
self._read_loop_down = Deferred()
# read queue timeout
self.q_timeout = 1
# read loop call
self._rloop_call = None
self._sloop_call = None
self.read_queue = None
self.read_chan = None
kwargs['heartbeat'] = kwargs.get('heartbeat', 10)
# failure traps
#self.log.warning('AUTO SHUTDOWN 15 sec')
#reactor.callLater(15, lambda _: self.shutdown_protocol(), (None,))
self.__messages = set()
AMQClient.__init__(self, *args, **kwargs)
示例2: connectionMade
def connectionMade(self):
"""
Hook called when the connection is made; we'll use this to perform
exchange setup, etc.
"""
try:
connectionInfo = self.factory.connectionInfo
set_keepalive(self.transport.socket, connectionInfo.amqpconnectionheartbeat)
AMQClient.connectionMade(self)
log.debug('Made initial connection to message broker')
self._connected = False
# Authenticate
try:
yield self.start({'LOGIN':connectionInfo.user, 'PASSWORD':connectionInfo.password})
self.factory.onAuthenticated(True)
log.debug('Successfully authenticated as %s' % connectionInfo.user)
except Exception as e:
log.warn("Error authenticating to %s as %s" % (connectionInfo.host, connectionInfo.user))
self.factory.onAuthenticated(e.args[0])
return
# Get a channel
self.chan = yield self.get_channel()
self._connected = True
# Initialize the queues
yield self.begin_listening()
# Call back our deferred
self.factory.onConnectionMade(self)
# Flush any messages that have been sent before now
yield self.send()
returnValue(None)
except Exception:
log.exception("Unable to connect")
示例3: __init__
def __init__(self, *args, **kwargs):
self.log.debug('init protocol')
self._stop = False
# callback on authenticated
self._auth_succ = Deferred()
# callback on read_channel opened
self._read_opened = Deferred()
# callback on write_channel opened
self._write_opened = Deferred()
# callback on read_loop started
self._read_loop_started = Deferred()
# callback on shutdown read loop
self._read_loop_down = Deferred()
# read queue timeout
self.q_timeout = 1
# read loop call
self._rloop_call = None
self._sloop_call = None
# ensure that we start read loop only once
self._read_loop_enabled = False
self.read_queue = None
self.read_chan = None
kwargs['heartbeat'] = kwargs.get('heartbeat', 10)
self.__messages = set()
AMQClient.__init__(self, *args, **kwargs)
示例4: connectionMade
def connectionMade(self):
AMQClient.connectionMade(self)
# Authenticate.
assert self.factory is not None
deferred = self.start({"LOGIN": self.factory.user,
"PASSWORD": self.factory.password})
deferred.addCallbacks(self._authenticated, self._authentication_failed)
示例5: AMQFactory
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()
示例6: connectionMade
def connectionMade(self):
AMQClient.connectionMade(self)
yield self.authenticate(self.vumi_options['username'],
self.vumi_options['password'])
# authentication was successful
log.msg("Got an authenticated connection")
yield self.connected_callback(self)
示例7: makeConnection
def makeConnection(self, transport):
'''
This only for debug errors
'''
try:
AMQClient.makeConnection(self, transport)
except Exception, mess:
self.log.error('During makeConnection: %r'%mess)
示例8: connectionLost
def connectionLost(self, reason):
"""
Remove this protocol as a consumer of log events.
"""
self.chan = None
self.dispatcher.unregister(self.producer.put)
log.err(reason, "Connection lost")
AMQClient.connectionLost(self, reason)
示例9: connectionMade
def connectionMade(self):
"""Called when a connection has been made."""
AMQClient.connectionMade(self)
# Flag that this protocol is not connected yet.
self.connected = False
# Authenticate.
deferred = self.authenticate(self.factory.user, self.factory.password)
deferred.addCallback(self._authenticated)
deferred.addErrback(self._authentication_failed)
示例10: connectionMade
def connectionMade(self):
AMQClient.connectionMade(self)
# set that we are not connected
# since we should authenticate and open channels
self.connected = False
self.log.debug('go authentication %r'%self.factory.user)
d = self.authenticate(self.factory.user, self.factory.password)
d.addCallback(self._authenticated)
d.addErrback(self._error)
return d
示例11: __init__
def __init__(self, *args, **kwargs):
AMQClient.__init__(self, *args, **kwargs)
if self.check_0_8():
self.replyToField = "reply to"
else:
self.replyToField = "reply-to"
self.thriftBasicReturnQueueLock = defer.DeferredLock()
self.thriftBasicReturnQueues = {}
示例12: connectionMade
def connectionMade(self):
"""
authenticate and start the Node
"""
AMQClient.connectionMade(self)
username = self.factory.username
password = self.factory.password
# authentication should happen automatically, and fail asap
# XXX need to know how it can fail still
d = self.authenticate(username, password)
d.addCallback(self._auth_result)
d.addErrback(self._auth_fail)
示例13: connectionMade
def connectionMade(self):
"""
Add this protocol as a consumer of log events.
"""
AMQClient.connectionMade(self)
def eb(failure):
log.err(failure)
self.transport.loseConnection()
d = self.gotConnection()
d.addErrback(eb)
示例14: connectionMade
def connectionMade(self):
"""Called when a connection has been made."""
AMQClient.connectionMade(self)
# Flag that this protocol is not connected yet.
self.connected = False
self.consumer_tags = {}
# Authenticate.
deferred = self.start({"LOGIN": self.factory.user, "PASSWORD": self.factory.password})
deferred.addCallback(self._authenticated)
deferred.addErrback(self._authentication_failed)
示例15: __init__
def __init__(self, dispatcher, username='guest', password='guest',
vhost='/', exchange='logs', queueSize=None):
self.dispatcher = dispatcher
self.username = username
self.password = password
self.exchange = exchange
self.queueSize = queueSize
self.chan = None
specDir = FilePath(__file__).parent()
specFilePath = specDir.child('amqp0-9-1.extended.xml')
spec = txamqp.spec.load(specFilePath.path)
delegate = TwistedDelegate()
AMQClient.__init__(self, delegate=delegate, vhost=vhost,
spec=spec)