3

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

James
  • 79
  • 1
  • 6
  • 1
    @Stephen C I just succeed to create a task with Java send to Rabbitmq, and the celery could handle the task. But the code is very ugly, lots hard code to create the serialization string, not flexible at all. Is there some jar package could encapsulate these thing ? could make it work like python did, just create a task through call the function? – James Feb 07 '13 at 09:30

2 Answers2

5

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

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Hi Stephen, thanks, I have similiar idea as you said(Better to update my question to be more clear). Is there more clear demo project already which already integrate the steps you mentioned together? – James Feb 06 '13 at 09:44
  • 1
    I haven't Googled for one ... but you could. – Stephen C Feb 06 '13 at 11:45
  • I'm looking for something similar but I cannot find the details as far as which exchanges/queues to hook up to. How to retrieve results, etc. – eric.frederich Aug 15 '13 at 16:40
1

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

salva
  • 11
  • 1