All Projects → alexpusch → Queuelite.js

alexpusch / Queuelite.js

Super simple Node.js message queue for fun and prototyping

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Queuelite.js

Xxl Mq
A lightweight distributed message queue framework.(分布式消息队列XXL-MQ)
Stars: ✭ 358 (+411.43%)
Mutual labels:  message-queue
Jafka
a fast and simple distributed publish-subscribe messaging system (mq)
Stars: ✭ 697 (+895.71%)
Mutual labels:  message-queue
Carmine
Redis client and message queue for Clojure
Stars: ✭ 999 (+1327.14%)
Mutual labels:  message-queue
Nats Operator
NATS Operator
Stars: ✭ 471 (+572.86%)
Mutual labels:  message-queue
Siberite
Siberite is a simple, lightweight, leveldb backed message queue written in Go.
Stars: ✭ 583 (+732.86%)
Mutual labels:  message-queue
Huststore
High-performance Distributed Storage
Stars: ✭ 806 (+1051.43%)
Mutual labels:  message-queue
Message Io
Event-driven message library for building network applications easy and fast.
Stars: ✭ 321 (+358.57%)
Mutual labels:  message-queue
K8s Nats Streaming
NATS Streaming Server on Kubernetes
Stars: ✭ 58 (-17.14%)
Mutual labels:  message-queue
Weevent
Event-Driven Architecture Based on Blockchain.基于区块链的事件驱动架构
Stars: ✭ 608 (+768.57%)
Mutual labels:  message-queue
Toro
Multithreaded message processing on Postgres
Stars: ✭ 39 (-44.29%)
Mutual labels:  message-queue
Nsq
A realtime distributed messaging platform (forked from https://github.com/nsqio/nsq)
Stars: ✭ 476 (+580%)
Mutual labels:  message-queue
Taskq
Golang asynchronous task/job queue with Redis, SQS, IronMQ, and in-memory backends
Stars: ✭ 555 (+692.86%)
Mutual labels:  message-queue
Message Queue
第四届阿里中间件性能挑战赛复赛-JAVA-第21名
Stars: ✭ 16 (-77.14%)
Mutual labels:  message-queue
Nsq
A realtime distributed messaging platform
Stars: ✭ 20,663 (+29418.57%)
Mutual labels:  message-queue
Enqueue Elastica Bundle
The bundle extends functionality of FOSElasticaBundle. Improves performance of fos:elastica:populate command
Stars: ✭ 40 (-42.86%)
Mutual labels:  message-queue
Pmq
信也科技MQ消息系统
Stars: ✭ 333 (+375.71%)
Mutual labels:  message-queue
Rmq
Message queue system written in Go and backed by Redis
Stars: ✭ 722 (+931.43%)
Mutual labels:  message-queue
Kubemq
KubeMQ is Enterprise-grade message broker native for Docker and Kubernetes
Stars: ✭ 58 (-17.14%)
Mutual labels:  message-queue
Lemon Rabbitmq
乐檬框架之rabbitMQ的解耦实现方式(基于springboot框架),利用ConfirmCallback确保消息安全发送至broker服务器,使用Ack/Nack手动确认消息处理状态,保证broker消息被正确消费
Stars: ✭ 46 (-34.29%)
Mutual labels:  message-queue
Storage Based Queue
Javascript queue library with persistent storage based queue mechanism for the browsers environments. Specially designed for offline.
Stars: ✭ 33 (-52.86%)
Mutual labels:  message-queue

Super simple, persistent, no dependency on any db message queue

Travis status Maintainability

Have you ever played around with an idea, some side project, and figured out you need a message queue? Maybe you don't want to hassle yourself with an actual message queue, setup Rabbitmq or Kafka, learn about some Redis dependant solution or anything professional as such.

queuelite.js is a super simple, no-server, local, persistent, supports multiple publishers/consumers message queue.

The gist of it

There is only one queue, there are no channels, exchanges or any kind of higher level abstraction.

The queue is managed using the file system in a given data directory.

Why would you need this?

A job queue, or message queue can be extremely useful tools. Whenever a long computational task is composed out of a large number of small tasks, it can be beneficial to use a queue to manage it. The queue will handle failures, re-tries, distribution of work and other non trivial task.

There are many job/message queue solutions, some dedicated solutions as RabbitMQ, or some db dependant solutions as kue (Redis)

Queuelite is designed to be as simple to use as possible. It requires no other db, nor any additional setup.

Example

Suppose we want have a list of 1M file urls that we need to download and do something with. For this task we will create two files: publisher.js, and consumer.js. The publisher will publish messages containing individual files urls, the consumer will be called for each url and process it.

//publisher.js
const queuelite = require('queuelite');

queuelite.connect('./queue_data').then(queue => {
  queue.publish({url: 'http://example.com/file1'});
  queue.publish({url: 'http://example.com/file2'});
  queue.publish({url: 'http://example.com/file3'});
  //...
})
//consumer.js
const queuelite = require('queuelite');
const request = require('request-promise');

queuelite.connect('./queue_data').then(queue => {
  queue.consume((message) => {
    return request(message.url).then(doSomethingWithFile);
  })
})

Use PM2 to parallelize work

A very useful addition for our solution is the ability to parallelize our work. We can achieve this using the excellent PM2 process manager. All we need to do is to make it run several consumer.js processes:

pm2 start consumer.js -i 12 And just like that we have 12 managed instances of our consumer.

API

const Queuelite = require('queuelite');

Queuelite.connect

const queue = await Queuelite.connect(dataDirectory)

Creates a new instance of queuelite. Returns a promise that resolved to the queue instance

  • dataDirectory - directory queuelite stores message files in

queue.publish

queue.publish(message, options);

Publishes a new message to the job queue. Returns a promise that resolves when publishing is done

  • message - plain js object containing message data
  • options - (optional) plain js object containing extra options for processing the message
    • priority - You can change the order that messages are being consumed by setting a priority between 1 and 9. The default priority is 5. There are no assurances that messages with some priority will be processed fully before an other messages with a lower priority, just that they will be read in order of priority.

queue.consume

queue.consume((message, metadata /* {tryCount} */) => { 
  // return a promise
});

Defines the consumer of the queue. The handler method would be called for each published message.

  • message: The plain javascript object published for this message
  • metadata:
    • tryCount: number of times this message have been consumed and rejected.

Different processes can define a consumer on the same data directory. Queuelite will try to make sure each message is only consumed by a single process

consume handler should return a promise:

  • resolved promise: indicates that the message was consumed successfully.
  • rejected promise: indicates that consuming the message have failed, and you wish to retry consuming it.
  • rejected promise with Queuelite.ABORT: indicates that consuming the message have failed, and you do not wish to retry consuming it. The aborted message is stored in an 'abort' directory in the data directory.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].