Skip to content

Instantly share code, notes, and snippets.

@gaufung
Created September 12, 2020 13:36
Show Gist options
  • Save gaufung/23b363d7acae0c1f828d3a3fdbffb5d2 to your computer and use it in GitHub Desktop.
Save gaufung/23b363d7acae0c1f828d3a3fdbffb5d2 to your computer and use it in GitHub Desktop.
rabbitmq_asynchronous_channel.py
def _create_channel(self, connection):
self.logger.info("creating channel")
future = Future()
def on_channel_closed(channel, reply_code, reply_txt):
if reply_code not in [self._NORMAL_CLOSE_CODE, self._USER_CLOSE_CODE]:
self.logger.error("channel closed. reply code: %s; reply text: %s. system will exist"
% (reply_code, reply_txt,))
sys.exit(self._EXIST_CODE)
def open_callback(channel):
self.logger.info("created channel")
channel.add_on_close_callback(on_channel_closed)
future.set_result(channel)
connection.channel(on_open_callback=open_callback)
return future
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment