What is the best way to repeat posting messages with combo?

I am testing how a combo works. I plan to replace pika in several projects. I see that the combo has a lot of documentation, but using what I found in the documentation, some messages are lost. Here is the code:

from kombu import Connection, Producer conn = Connection('amqp://localhost:5672') def errback(exc, interval): logger.error('Error: %r', exc, exc_info=1) logger.info('Retry in %s seconds.', interval) producer = Producer(conn) publish = conn.ensure(producer, producer.publish, errback=errback, max_retries=3) for i in range(1, 200000): publish({'hello': 'world'}, routing_key='test_queue') time.sleep(0.001) 

When it is published, I close the connection several times, and it continues to publish, but there are about 60,000 messages in the queue, so there are a lot of lost messages.

I tried different options, for example:

 publish({'hello': 'world'}, retry=True, mandatory=True, routing_key='hipri') 

Thanks!

+6
source share
1 answer

The problem was that by default Kombu does not use 'confirm', you should use:

  conn = Connection('amqp://localhost:5672', transport_options={'confirm_publish': True}) 

thanks

+10
source

All Articles