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' => '',
$msg = new AMQPMessage(json_encode($data));
$channel->basic_publish($msg, $exchange);

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

def mytask(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":""}' (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?

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


  • 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.

    点赞 评论 复制链接分享