Skip to content

Latest commit

 

History

65 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

celery4j

A Java 17 library that speaks the Celery task protocol: send tasks to Celery workers, run the tasks Celery sends, and read the results either side leaves behind. No bridge, no adapter, no Python in the way.

  • Celery protocol version 2 and version 1, bodies in JSON

  • Redis and AMQP brokers, routed through an exchange where a deployment wants one, and a Redis result backend

  • A worker that carries on the chain and the handlers a task names, a fleet of them, and a client to ask with

  • Checked against a real Celery worker and producer in containers

Install

<dependency>
  <groupId>io.github.andreoss</groupId>
  <artifactId>celery4j</artifactId>
  <version>1.3.0</version>
</dependency>

Quick start

Send a task to a Celery worker:

try (
    Broker broker = new RedisBroker(new JedisPool(URI.create("redis://localhost:6379/0")));
    Backend backend = new RedisBackend(new JedisPool(URI.create("redis://localhost:6379/0")))
) {
    Object sum = new Client(broker, backend)
        .delay("examples.add", 2, 3)
        .value(Duration.ofSeconds(10))
        .orElseThrow();
}

Run the tasks Celery sends, by name:

new Worker(
    broker,
    backend,
    new Registry(Map.of("examples.add", task -> (int) task.args().get(0) + (int) task.args().get(1)))
).some("celery", Duration.ofSeconds(5), 10);

Examples

examples/ holds one app on each side of the wire:

  • CeleryApp.java, which produces or consumes with this library

  • celery_app.py, the same app in Python

Start a broker, then run either side:

docker run -d -p 6379:6379 redis:7-alpine

mvn -q package -DskipTests
mvn -q dependency:build-classpath -Dmdep.outputFile=cp.txt
java -cp "target/classes:$(cat cp.txt)" examples/CeleryApp.java consume   # or produce

(cd examples && celery -A celery_app worker)    # the other side
(cd examples && python celery_app.py produce)

Build

mvn verify           # its own cases, and the quality gate
mvn verify -Plive    # adds the cases that talk to Celery and to real services

Needs Java 17 to run, a newer one to build, and a container runtime for the live cases.

Licence

Copyright (c) 2023-2026. MIT, see LICENSE.txt.

About

Celery task protocol in Java 17 - send tasks to Celery workers, run the tasks Celery sends, read results.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages