I am facing below issue regarding RabbitMQ consumers.
Issue
When RabbitMQ consumers are idle for a day, then the consumer is removed automatically (maybe the connection is closed). The exact issue is that the consumer script is still running. If consumer is closed then the below consumer script should be stopped. The consumer is removed silently and script is still running so I am not notified when consumer is closed unless I look into RabbitMQ console manually. I have some mechanism that notifies when script is stopped running, but here consumer is removed and script is still running and not able to be notified when consumer is removed automatically if it is idle for a day.
run.py (consumer script)
import pika
def main():
parameters = pika.URLParameters(amqp_url)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.queue_declare(queue='hello')
def callback(ch, method, properties, body):
print(" [x] Received %r" % body)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(queue='hello', on_message_callback=callback, auto_ack=False)
print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
if __name__ == '__main__':
main()
requirements.txt
pika=1.1.0
Metadata
pika version: 1.1.0
heartbeat: 60s
script is deployed in Kubernetes docker container
Project structure
- requirements.txt
- run.py
DockerFile
FROM python:3.9-slim
WORKDIR /consumer
ADD requirements.txt ./
RUN pip install --upgrade pip==20.2.4
RUN pip install -r requirements.txt
ADD . ./
CMD python run.py