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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器