예제 #1
0
 def setUp(self):
     super(AMQPumpTest, self).setUp()
     delegate = TwistedDelegate()
     spec = load(DEFAULT_SPEC)
     self.client = AMQClient(delegate, "/", spec, clock=Clock())
     self.transport = AMQPump()
     self.transport.connect(self.client)
예제 #2
0
 def connect_to_exchange(self):
     """
     Connect to an AMQP exchange as a publisher.
     """
     exchange = self.pub_exchange
     vhost = self.pub_vhost
     user = self.pub_user
     passwd = self.pub_passwd
     endpoint_s = self.pub_endpoint_s
     spec = self.pub_spec
     e = clientFromString(self.reactor, endpoint_s)
     delegate = TwistedDelegate()
     amqp_protocol = AMQClient(
         delegate=delegate,
         vhost=vhost,
         spec=spec)
     try:
         conn = yield connectProtocol(e, amqp_protocol)
     except Exception:
         self.log.failure(
             "Failed to establish AMQP connection to endpoint '{0}'".format(
                 endpoint_s))
         raise
     yield conn.authenticate(user, passwd)
     self.pub_channel = yield conn.channel(1)
     yield self.pub_channel.channel_open()
예제 #3
0
 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
예제 #4
0
 def setUp(self):
     super(AMQClientTest, self).setUp()
     self.delegate = TwistedDelegate()
     self.clock = Clock()
     self.heartbeat = 1
     self.protocol = AMQClient(
         self.delegate, "/", load(DEFAULT_SPEC), clock=self.clock,
         heartbeat=self.heartbeat)
     self.transport = AMQPump(Logger())
     self.transport.connect(self.protocol)
예제 #5
0
    def connect(self):
        host = self.host
        port = self.port
        spec = self.spec
        user = self.username
        password = self.password
        vhost = self.vhost
        delegate = TwistedDelegate()
        onConn = Deferred()
        p = AMQClient(delegate, vhost, txamqp.spec.load(spec), heartbeat=0)
        f = protocol._InstanceFactory(reactor, p, onConn)
        c = reactor.connectTCP(host, port, f)

        def errb(thefailure):
            thefailure.trap(error.ConnectionRefusedError)
            logging.error(traceback.format_exc())

        onConn.addErrback(errb)
        client = yield onConn
        self.client = client
        yield self.authenticate(self.client, user, password)
        returnValue(client)
예제 #6
0
    def start_amqp_client(self):
        amqp_info = self.amqp_info
        log = self.amqp_log
        endpoint_str = amqp_info['endpoint']
        vhost = amqp_info['vhost']
        spec_path = amqp_info['spec']
        queue_name = amqp_info['queue']
        user = amqp_info['user']
        passwd = amqp_info['passwd']
        creds = (user, passwd)
        log.debug(
            "endpoint='{endpoint}', vhost='{vhost}', user='******', queue={queue}",
            endpoint=endpoint_str,
            vhost=vhost,
            user=user,
            spec=spec_path,
            queue=queue_name)
        delegate = TwistedDelegate()
        spec = txamqp.spec.load(spec_path)
        try:
            ep = clientFromString(self.reactor, endpoint_str)
        except filepath.UnlistableError as ex:
            msg = "One of the file paths in endpoint string '{0}' could not be listed.".format(
                endpoint_str)
            d = self.reactor.callLater(0, self.reactor.stop)
            raise EndpointError(msg)

        d = connectProtocol(
            ep, AMQClient(delegate=delegate, vhost=vhost, spec=spec))
        d.addCallback(self.on_amqp_connect, queue_name, creds)

        def onError(err):
            if reactor.running:
                log.failure(err)
                reactor.stop()

        d.addErrback(onError)