Skip to content

Instantly share code, notes, and snippets.

@gaufung
Created September 12, 2020 13:42
Show Gist options
  • Save gaufung/0e058edb6d8e9b01fd9a24dbfea318d6 to your computer and use it in GitHub Desktop.
Save gaufung/0e058edb6d8e9b01fd9a24dbfea318d6 to your computer and use it in GitHub Desktop.
Rabbitmq asynchronous publish
@gen.coroutine
def publish(self, exchange, routing_key, body, properties=None):
"""
publish message. creating a brand new channel once invoke this method. After publishing, it closes the
channel.
:param exchange: exchange name
:type exchange; str or unicode
:param routing_key: routing key (e.g. dog.yellow, cat.big)
:param body: message
:param properties: properties
:return: None
"""
self.logger.info("[publishing] exchange: %s; routing key: %s; body: %s." % (exchange, routing_key, body,))
channel = yield self._create_channel(self._publish_connection)
channel.basic_publish(exchange=exchange, routing_key=routing_key, body=body, properties=properties)
channel.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment