douxianliu6756 2014-09-29 08:08
浏览 181
已采纳

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

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 2014-09-29 08:30
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题