Springboot starter for celery using celery-java, which is Java implementation of Celery client and worker. Quoting from the project website:
Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well.
The execution units, called tasks, are executed concurrently on a single or more worker servers using multiprocessing, Eventlet, or gevent. Tasks can execute asynchronously (in the background) or synchronously (wait until ready).
Celery is used in production systems to process millions of tasks a day.
For more info, celery-java
The aim is to be compatible with existing Python Celery implementation. That means you should be able to run a Java client with a Python worker or vice-versa. Tested with Python Celery 5.1.
Releases are available from Maven Central. Latest version:
<dependency>
<groupId>vip.appcity</groupId>
<artifactId>celery-spring-boot-starter</artifactId>
<version>...</version>
</dependency>
Snapshots are available from Sonatype OSRH:
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
celery:
queue: "demo:celery"
broker: amqp://guest:guest@localhost:5672/vhost
# backend:
@celery.task(name='test.dummy_task')
def dummy_task(num):
print(num)
return "finished"
Call the task by name in java
@Resource
private Celery celery;
celery.submit("test.dummy_task", new Object[]{1});
celery:
enabled: true
enableMultiQueue: true
queue: "demo:celery"
broker: amqp://guest:guest@localhost:5672/vhost
# backend:
taskQueueMaps:
"test.dummy_task": "celery"
"test.dummy_task2": "celery"
"test.dummy_task3": "celery1"
"test.dummy_task4": "celery2"
Call the task by name in java
@Resource
private CeleryTaskDistributor celeryTaskDistributor;
celeryTaskDistributor.submit("test.dummy_task", new Object[]{1});