Can I use java send task to celery through rabbitmq?

China☆狼群 提交于 2019-12-20 02:30:40

问题


I just touch celery and java for 2 days. :(

Right now, I have a task that java client send task through rabbitmq. Celery will be the worker to handle task.

I know it's easy for Python->rabbitmq->celery. But can I do this by java->rabbitmq->celery ?

The draft idea is that serialization the java function by JSON and then send by rabbitmq, and then handle by celery.

It's better to have example code and could be run directly

thanks


回答1:


You can certainly send messages through RabbitMQ from Java. There is a Java client-side library for interfacing with RabbitMQ - http://www.rabbitmq.com/api-guide.html

This page describes the Celery message format - http://docs.celeryproject.org/en/latest/internals/protocol.html. One flavour uses JSON, and there are lots of existing Java libraries for reading and writing in JSON; see http://json.org

It's better to have example code and could be run directly

You are correct.

The page linked above includes code snippets, and the RabbitMQ Java library has some (small) examples. (At least, that's what the page says.)




回答2:


Simplest form would be to write a simple python script which simply adds a task to celery, and call this python script from java (Runtime.exec() or similar method).



来源:https://stackoverflow.com/questions/14724910/can-i-use-java-send-task-to-celery-through-rabbitmq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!