def setupConnectivity(self): while self.loop(): try: self.connection = amqp_connection(host=self.host, port=self.port, virtual_host=self.vhost, userid=self.user, password=self.password) self.channel = self.connection.channel() if self.exchange != "": self.channel.exchange_declare(self.exchange, self.exchange_type, durable=self.exchange_durable) self.logging.debug("Declared exchange %s." % (self.exchange)) if self.queue_declare: self.channel.queue_declare(self.queue, durable=self.queue_durable, exclusive=self.queue_exclusive, auto_delete=self.queue_auto_delete) self.logging.debug("Declared queue %s." % (self.queue)) if self.exchange != "": self.channel.queue.bind(self.queue, self.exchange, routing_key=self.routing_key) self.logging.debug("Bound queue %s to exchange %s." % (self.queue, self.exchange)) self.channel.basic_qos(prefetch_size=0, prefetch_count=self.prefetch_count, a_global=False) self.channel.basic_consume(self.queue, callback=self.consume, no_ack=self.no_ack) self.logging.info("Connected to broker.") except Exception as err: self.logging.error("Failed to connect to broker. Reason %s " % (err)) sleep(1) else: spawn(self.drain) break
def setupConnectivity(self): while self.loop(): try: self.connection = amqp_connection(host=self.host, port=self.port, virtual_host=self.vhost, userid=self.user, password=self.password) self.channel = self.connection.channel() if self.exchange != "": self.channel.exchange_declare(self.exchange, self.exchange_type, durable=self.exchange_durable) self.logging.debug("Declared exchange %s." % (self.exchange)) if self.queue != "": self.channel.queue_declare(self.queue, durable=self.queue_durable, exclusive=self.queue_exclusive, auto_delete=self.queue_auto_delete) self.logging.debug("Declared queue %s." % (self.queue)) if self.exchange != "" and self.queue != "": self.channel.queue.bind(self.queue, self.exchange, routing_key=self.routing_key) self.logging.debug("Bound queue %s to exchange %s." % (self.queue, self.exchange)) self.logging.info("Connected to broker.") break except Exception as err: self.logging.error("Failed to connect to broker. Reason %s " % (err)) sleep(1)
def setupConnectivity(self): while self.loop(): try: self.connection = amqp_connection(host=self.host, port=self.port, virtual_host=self.vhost, userid=self.user, password=self.password) self.channel = self.connection.channel() if self.exchange != "": self.channel.exchange_declare( self.exchange, self.exchange_type, durable=self.exchange_durable) self.logging.debug("Declared exchange %s." % (self.exchange)) if self.queue != "": self.channel.queue_declare( self.queue, durable=self.queue_durable, exclusive=self.queue_exclusive, auto_delete=self.queue_auto_delete) self.logging.debug("Declared queue %s." % (self.queue)) if self.exchange != "" and self.queue != "": self.channel.queue.bind(self.queue, self.exchange, routing_key=self.routing_key) self.logging.debug("Bound queue %s to exchange %s." % (self.queue, self.exchange)) self.logging.info("Connected to broker.") break except Exception as err: self.logging.error("Failed to connect to broker. Reason %s " % (err)) sleep(1)