douxianliu6756
douxianliu6756
2014-09-29 08:08

为什么芹菜不处理消息并删除它?

已采纳

I'm using php to send the message to rabbitmq and a python consumer to process it. Here is what I did.

This part send a json to rabbitmq.

$data = array(
  'id' => 123,
  'url' => 'baidu.com',
);
$msg = new AMQPMessage(json_encode($data));
$channel->basic_publish($msg, $exchange);

And this part receive the message and process it (using celery).

@app.task
def mytask(json_obj):
    print(json_obj)
    data = json.loads(json_obj)
    thread_id = data['id']
    url = data['url']
    return py_read(thread_id, url)

Here is what I get from the console:

[2014-09-29 15:51:34,564: WARNING/MainProcess] celery@mickey-Thurley ready.
[2014-09-29 15:51:37,395: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?

The full contents of the message body was: body: '{"id":123,"url":"baidu.com"}' (28b)
{content_type:None content_encoding:None
  delivery_info:{'redelivered': False, 'routing_key': '', 'exchange': 'celery', 'delivery_tag': 1, 'consumer_tag': '4'} headers={}}

I'm sure that the consumer received the message, but why the message didn't be processd? and what should I do to deal with it?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doulu2591 doulu2591 7年前

    A Celery task is not simply data. You also need to have something that tells the worker what task you are actually calling, and that's missing from your message.

    Rather than trying to implement this yourself, you should probably use one of the Celery PHP implementations that are out there, such as this one.

    点赞 评论 复制链接分享

相关推荐