Skip to content

Instantly share code, notes, and snippets.

@gaufung
Created September 12, 2020 13:40
Show Gist options
  • Save gaufung/543600e12910c6cdf0d4aba8d6efc7f8 to your computer and use it in GitHub Desktop.
Save gaufung/543600e12910c6cdf0d4aba8d6efc7f8 to your computer and use it in GitHub Desktop.
Exhcnage queue and routing key
def _exchange_declare(self, channel, exchange=None, exchange_type='topic', **kwargs):
self.logger.info("declaring exchange: %s " % exchange)
future = Future()
def callback(unframe):
self.logger.info("declared exchange: %s" % exchange)
future.set_result(unframe)
channel.exchange_declare(callback=callback,
exchange=exchange, exchange_type=exchange_type, **kwargs)
return future
def _queue_declare(self, channel, queue='', **kwargs):
self.logger.info("declaring queue: %s" % queue)
future = Future()
def callback(method_frame):
self.logger.info("declared queue: %s" % method_frame.method.queue)
future.set_result(method_frame.method.queue)
channel.queue_declare(callback=callback, queue=queue, **kwargs)
return future
def _queue_bind(self, channel, queue, exchange, routing_key=None, **kwargs):
self.logger.info("binding queue: %s to exchange: %s" % (queue, exchange,))
future = Future()
def callback(unframe):
self.logger.info("bound queue: %s to exchange: %s" % (queue, exchange,))
future.set_result(unframe)
channel.queue_bind(callback, queue=queue, exchange=exchange, routing_key=routing_key, **kwargs)
return future
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment