Created
September 12, 2020 13:42
-
-
Save gaufung/0e058edb6d8e9b01fd9a24dbfea318d6 to your computer and use it in GitHub Desktop.
Rabbitmq asynchronous publish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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