def connect(self, protocol_factory):
"""
Connect to the C{protocolFactory} to the AMQP broker specified by the
URI of this endpoint.
@param protocol_factory: An L{AMQFactory} building L{AMQClient} objects.
@return: A L{Deferred} that results in an L{AMQClient} upon successful
connection otherwise a L{Failure} wrapping L{ConnectError} or
L{NoProtocol <twisted.internet.error.NoProtocol>}.
"""
# XXX Since AMQClient requires these parameters at __init__ time, we
# need to override them in the provided factory.
protocol_factory.set_vhost(self._vhost)
protocol_factory.set_heartbeat(self._heartbeat)
description = "tcp:{}:{}:timeout={}".format(
self._host, self._port, self._timeout)
endpoint = clientFromString(self._reactor, description)
deferred = endpoint.connect(protocol_factory)
return deferred.addCallback(self._authenticate)
评论列表
文章目录