Taylor Lopez
Taylor Lopez

Reputation: 863

How to skip old messages when connecting to a RabbitMQ producer

I've looked into the expiration and TTL policies for messages and queues, but I'm not sure if that's the best way to accomplish what I'm trying to do.

Ideally, when my consumer connects to my sender, I want to skip any old, unreceived messages, and only receive messages that are sent after connection. In Kafka, this was accomplished by configuring the consumer to essentially seek the queue to the end before beginning the consumption of more messages. A direct RabbitMQ equivalent to this feature didn't seem to exist, but I have to imagine there's a more efficient way to accomplish this without making the TTL or expiration on the messages to be very short.

How do I consume only messages received after connecting to a RabbitMQ producer?

Upvotes: 1

Views: 688

Answers (1)

Taylor Lopez
Taylor Lopez

Reputation: 863

What ended up working for us was configuring the producer during publishing rather than configuring the consumer.

channel.basic_publish([other params], properties=pika.BasicProperties(expiration='1000'))

This causes the messages to expire after one second, which was good enough for our needs.

Upvotes: 1

Related Questions