start_consuming sigterm graceful shutdown

16 views
Skip to first unread message

Mauricio Villegas

unread,
Jan 30, 2024, 7:27:23 AMJan 30
to Pika
Hello,

I am new to pika. I searched online and I didn't find an answer to what I need.

I am using kubernetes and I need to make sure that my service does a proper graceful shutdown. I have a consumer with code like:
def start_consuming(self):
try:
self.channel.start_consuming()
except KeyboardInterrupt:
logger.info("keyboard interrupt")
self.channel.stop_consuming()
except Exception:
logger.critical("unexpected exception")
raise
finally:
self.connection.close()
logger.info("connection closed")
logger.info("ended consuming")

When I do a keyboard interrupt, in the logs I correctly see the four messages. Also in rabbitmq I see an info closing connection log. However, if I send a SIGTERM to the process (which is what kubernetes does), there are no logs. Then only thing I see is "Terminated". And in the rabbitmq log I see two warnings saying that the connection was unexpectedly closed.

Is this the normal behavior? The only way to implement a graceful shutdown is to register a signal handler?

Thank you!

Best,
Mauricio


Luke Bakken

unread,
Jan 30, 2024, 11:33:33 AMJan 30
to Pika
Reply all
Reply to author
Forward
0 new messages