celery written in nodejs
npm install celery-nodeCelery client / worker for in node.js
This project focuses on implementing task queue using celery protocol in node.js influenced by node-celery
But managing messages is not as simple as storing them in a data sotre as aqueue.
Suppose that a number of messages sent and dispatched by large number of producers and workers.
We have to consider below.
- Detecting poison messages
- Ensuring reliability of the messaging sysstem
- Scaling the messaging system
Celery is written in Python, but the protocol can be implemneted in any languages. There's gocelery for Go and like gocelery, here's celery.node.
client.conf.TASK_PROTOCOL = 1; // 1 or 2. default is 2.
`Install
`sh
$ npm install celery-node
`
Getting started
$3
#### celery.node
`javascript
const celery = require('celery-node');const client = celery.createClient(
"amqp://",
"amqp://"
);
const task = client.createTask("tasks.add");
const result = task.applyAsync([1, 2]);
result.get().then(data => {
console.log(data);
client.disconnect();
});
`
#### python
`python
from celery import Celeryapp = Celery('tasks',
broker='amqp://',
backend='amqp://'
)
@app.task
def add(x, y):
return x + y
if __name__ == '__main__':
result = add.apply_async((1, 2), serializer='json')
print(result.get())
`
$3
#### celery.node
`javascript
const celery = require('celery-node');const worker = celery.createWorker(
"amqp://",
"amqp://"
);
worker.register("tasks.add", (a, b) => a + b);
worker.start();
`
#### python
`python
from celery import Celeryapp = Celery('tasks',
broker='amqp://',
backend='amqp://'
)
@app.task
def add(x, y):
return x + y
`
`shellscript
$ celery worker -A tasks --loglevel=INFO
`
$3
Ensure you already installed nodejs, npm, and docker-compose
`sh
Generate dist/ directory, tutorial files depend on it
$ npm run diststart a docker container rabbitmq in the background
$ docker-compose -f examples/docker-compose.yml up -d rabbitrun celery.node client with rabbitmq
$ node examples/tutorial/client.jsrun celery.node worker with rabbitmq
when you run worker, you can see the result printed out from client
$ node examples/tutorial/worker.jsstop and remove containers
$ docker-compose -f examples/docker-compose.yml down
``