Reputation: 290
Below is my rabbitmq snippet. I am running long running task, connection is getting closed though my task continue to run in the background. Once the task is complete and I am trying to acknowledge the channel is closed. I tried to reconnect but Process Died as exception. What is the way to fix this? I do see this thread talks about using threading: Handling long running tasks in pika / RabbitMQ Handling long running tasks in pika / RabbitMQ But, then there are answer that inform pika not being thread safe. Any better solution? apart from threading and apart from setting heartbeat to 0?
class CreateSummary(RabbitBot):
def __init__(*args, **kwargs):
****
def generate_summary(self, ch, method, properties, body):
# parse body
# create summary based on the input
try:
ch.basic_ack(delivery_tag=method.delivery_tag)
except Exception as e:
try:
self._reconnect()
self._rabbitmq_channel.basic_ack(delivery_tag=method.delivery_tag)
except Exception as e:
raise e
def consume(self):
self._rabbitmq_channel.basic_qos(prefetch_count=1)
self._rabbitmq_channel.basic_consume(queue=self._rabbitmq_queue,
on_message_callback=self.generate_summary)
try:
self._rabbitmq_channel.start_consuming()
except (pika.exceptions.AMQPConnectionError,
pika.exceptions.AMQPChannelError,
pika.exceptions.ChannelWrongStateError) as e:
self._reconnect()
self.consume()
Upvotes: 1
Views: 84