Last active
December 10, 2015 20:28
-
-
Save udoprog/4487995 to your computer and use it in GitHub Desktop.
Celery and Distribution using routing_keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from celery import Celery | |
from kombu import Exchange | |
from kombu import Queue | |
# modify this to select which routing_key to consume. | |
SITE = 'sto' | |
celery = Celery() | |
celery.conf.update( | |
BROKER_URL='amqp://', | |
CELERY_RESULT_BACKEND='amqp://', | |
CELERY_QUEUES=[ | |
Queue(SITE, Exchange('myexchange'), routing_key=SITE) | |
] | |
) | |
log = logging.getLogger(__name__) | |
@celery.task(name="task") | |
def task(a, b): | |
log.info(SITE + ": got job") | |
return SITE + ": " + str(a + b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery import Celery | |
celery = Celery() | |
celery.conf.update( | |
BROKER_URL='amqp://', | |
CELERY_RESULT_BACKEND='amqp://', | |
CELERY_DEFAULT_EXCHANGE='myexchange', | |
) | |
jobs = [ | |
celery.send_task("task", (1000, 2000), routing_key='ash'), | |
celery.send_task("task", (1000, 2000), routing_key='sto'), | |
celery.send_task("task", (1000, 2000), routing_key='sto'), | |
celery.send_task("task", (1000, 2000), routing_key='sto'), | |
celery.send_task("task", (1000, 2000), routing_key='sto'), | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PYTHONPATH=$PWD celery worker --app consumer --loglevel INFO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment