Я пытаюсь опубликовать сообщение для Celery через RabbitMQ, используя библиотеку python Pika
Сообщение попадает в RabbitMQ, но взрывается, когда Селери обрабатывает его. У меня нет проблем, когда я реализую ту же концепцию с использованием .Net или Php, но я просто не могу заставить ее работать с использованием Python.
Подключение к RabbitMQ
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
Публикация сообщения:
def sendMsg():
#generate a unique ID
rd = random.Random()
rd.seed(0)
id = uuid.UUID(int=rd.getrandbits(128))
msg = '{"msg":"What if i fall? but son, what if you fly"}'
hrds = {'task': 'task.hello', 'id':str(id)}
properties = pika.BasicProperties(content_type='application/json',headers= hrds)
channel.basic_publish(exchange='celery',routing_key='celery',body=msg,properties=properties)
Обработчик задач Celery
@app.task
def hello(msg):
print("Your msg is: "+msg)
Ошибка сельдерея:
[2018-09-14 06:44:01,091: ERROR/MainProcess] Pool callback raised exception: ValueError('too many values to unpack (expected 3)',)
Traceback (most recent call last):
File "/home/devops/Documents/celery/workers/lib/python3.6/site-packages/kombu/utils/objects.py", line 42, in __get__
return obj.__dict__[self.__name__]
KeyError: 'chord'
During handling of the above exception, another exception occurred:
> Traceback (most recent call last): File
> "/home/devops/Documents/celery/workers/lib/python3.6/site-packages/billiard/pool.py",
> line 1747, in safe_apply_callback
> fun(*args, **kwargs) File "/home/devops/Documents/celery/workers/lib/python3.6/site-packages/celery/worker/request.py",
> line 366, in on_failure
> self.id, exc, request=self, store_result=self.store_errors, File "/home/devops/Documents/celery/workers/lib/python3.6/site-packages/celery/backends/base.py",
> line 157, in mark_as_failure
> if request.chord: File "/home/devops/Documents/celery/workers/lib/python3.6/site-packages/kombu/utils/objects.py",
> line 44, in __get__
> value = obj.__dict__[self.__name__] = self.__get(obj) File "/home/devops/Documents/celery/workers/lib/python3.6/site-packages/celery/worker/request.py",
> line 485, in chord
> _, _, embed = self._payload ValueError: too many values to unpack (expected 3)
Среда: Linux, Python: 3.6.5, Pika: 0.12.0