'Kombu Custom Consumer halt after certain amt of time without a new message

Is it possible for a Kombu Consumer to automatically stop running (maybe by setting self.should_stop = True?) after it fails to receive a message within 5 seconds? I have zero control over the producer.

Use Case: I subscribe to a queue. This queue will produce a finite number of messages in 30 seconds. I want to get all the messages and continue program execution.

Current code:

with Connection(host, ssl=True, connect_timeout=1) as conn:
    CustomConsumer(conn).run()

CustomConsumer implements on_task(self, body, message) and on_consume_end(self, connection, channel) which is never called.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source