Celery Tasks Go in Multiple Queues

I noticed that celery sends jobs to several queues, and workers in both queues complete tasks.

My definitions are in the queue:

CELERY_QUEUES = ( Queue('default', Exchange('default'), routing_key='default'), Queue('client1', Exchange('client1'), routing_key='client1'), Queue('images', Exchange('media'), routing_key='media.images'), ) 

And when, after stopping all my workers, I run:

 >>> tasks.ping.apply_async(queue='default') 

I see that the task is displayed in the default and client1 queues:

 $ redis-cli -c llen default (integer) 1 $ redis-cli -c llen client1 (integer) 1 

This applies only to the default queue. Sending it directly to client1 queue only adds there:

 >>> tasks.ping.apply_async(queue='client1') $ redis-cli -c llen default (integer) 1 $ redis-cli -c llen client1 (integer) 2 

The images queue never accepts tasks incorrectly.

This is celery 3.1.15 with the Redis broker.

+5
source share
1 answer

Good! It seems that the problem is that the Kombu Redis broker does not clear old exchanges + routing keys.

First I set up the queues:

 CELERY_QUEUES = ( Queue('default', Exchange('default'), routing_key='default'), Queue('client1', Exchange('default'), routing_key='default'), ) 

And later they changed them to use a separate exchange and routing key for client1 .

But for some reason, Combu did not clear the old bindings, so I stayed with:

 redis> smembers _kombu.binding.default 1) "default\x06\x16\x06\x16client1" 2) "default.client1\x06\x16\x06\x16client1" 3) "default\x06\x16\x06\x16default" 

So, tasks sent to default were sent to the default and client1 queues.

Fixed removal of incorrect bindings:

 redis> srem _kombu.binding.default "default\x06\x16\x06\x16client1" redis> srem _kombu.binding.default "default.client1\x06\x16\x06\x16client1" 
+7
source

Source: https://habr.com/ru/post/1234730/


All Articles