Abraxas is an end-to-end streaming Gearman client and worker library for Node.js. (Server implementation coming soon.)
https://www.npmjs.org/package/abraxas
Standout features:
- Support for workers handling multiple jobs at the same time over a single connection. This is super useful if your jobs tend to be bound by external resources (eg databases).
- Built streaming end-to-end from the start, due to being built on gearman-packet.
- Most all APIs support natural callback, stream and promise style usage.
- Support for the gearman admin commands to query server status.
- Delayed background job execution built in, with recent versions of the C++ gearmand.
Things I learned on this project:
- Nothing in the protocol stops clients and workers from sharing the same connection. This was imposed by arbitrary library restrictions.
- In fact, the plain text admin protocol can be included cleanly on the same connection as the binary protocol.
- Nothing stops workers from handling multiple jobs at the same time, except, again, arbitrary library restrictions.
- The protocol documentation on gearman.org is out of date when compared to the C++ gearmand implementation– notably, SUBMIT_JOB_EPOCH has been implemented. I’ve begun updating the protocol documentation here:
https://github.com/iarna/gearman-packet/blob/master/PROTOCOL.md
Because everything is a stream, you can do things like this:
process.stdin.pipe(client.submitJob('toUpper')).pipe(process.stdout);
Or as a promise:
client.submitJob('toUpper', 'test string').then(function (result) {
console.log("Upper:", result);
});
Or as a callback:
client.submitJob('toUpper', 'test string', function(error, result) {
if (error) console.error(error);
console.log("Upper:", result);
});
Or mix and match:
process.stdin.pipe(client.submitJob('toUpper')).then(function(result) {
console.log("Upper:", result);
});