All Projects → saintedlama → microq

saintedlama / microq

Licence: ISC license
Micro job queue built on mongo

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to microq

Nsq
A realtime distributed messaging platform
Stars: ✭ 20,663 (+30740.3%)
Mutual labels:  queue, messaging, message-queue
Nsq
A realtime distributed messaging platform (forked from https://github.com/nsqio/nsq)
Stars: ✭ 476 (+610.45%)
Mutual labels:  queue, messaging, message-queue
Storage Based Queue
Javascript queue library with persistent storage based queue mechanism for the browsers environments. Specially designed for offline.
Stars: ✭ 33 (-50.75%)
Mutual labels:  queue, message-queue
Toro
Multithreaded message processing on Postgres
Stars: ✭ 39 (-41.79%)
Mutual labels:  queue, message-queue
Php Fpm Queue
Use php-fpm as a simple built-in async queue
Stars: ✭ 103 (+53.73%)
Mutual labels:  queue, message-queue
Taskq
Golang asynchronous task/job queue with Redis, SQS, IronMQ, and in-memory backends
Stars: ✭ 555 (+728.36%)
Mutual labels:  queue, message-queue
Siberite
Siberite is a simple, lightweight, leveldb backed message queue written in Go.
Stars: ✭ 583 (+770.15%)
Mutual labels:  queue, message-queue
Foundatio
Pluggable foundation blocks for building distributed apps.
Stars: ✭ 1,365 (+1937.31%)
Mutual labels:  queue, messaging
Xxl Mq
A lightweight distributed message queue framework.(分布式消息队列XXL-MQ)
Stars: ✭ 358 (+434.33%)
Mutual labels:  queue, message-queue
Lightbus
RPC & event framework for Python 3
Stars: ✭ 149 (+122.39%)
Mutual labels:  queue, messaging
Bull
Premium Queue package for handling distributed jobs and messages in NodeJS.
Stars: ✭ 11,748 (+17434.33%)
Mutual labels:  queue, message-queue
Garagemq
AMQP message broker implemented with golang
Stars: ✭ 153 (+128.36%)
Mutual labels:  queue, messaging
Jocko
Kafka implemented in Golang with built-in coordination (No ZK dep, single binary install, Cloud Native)
Stars: ✭ 4,445 (+6534.33%)
Mutual labels:  queue, messaging
Bigq
Messaging platform in C# for TCP and Websockets, with or without SSL
Stars: ✭ 18 (-73.13%)
Mutual labels:  queue, messaging
Message Bus
Go simple async message bus
Stars: ✭ 166 (+147.76%)
Mutual labels:  queue, message-queue
Kubemq
KubeMQ is Enterprise-grade message broker native for Docker and Kubernetes
Stars: ✭ 58 (-13.43%)
Mutual labels:  queue, message-queue
orkid-node
Reliable and modern Redis Streams based task queue for Node.js 🤖
Stars: ✭ 61 (-8.96%)
Mutual labels:  queue, message-queue
jrsmq
A lightweight message queue for Java that requires no dedicated queue server. Just a Redis server.
Stars: ✭ 28 (-58.21%)
Mutual labels:  queue, message-queue
Rsmq
Redis Simple Message Queue
Stars: ✭ 1,556 (+2222.39%)
Mutual labels:  queue, message-queue
Laravel Queue
Laravel Enqueue message queue extension. Supports AMQP, Amazon SQS, Kafka, Google PubSub, Redis, STOMP, Gearman, Beanstalk and others
Stars: ✭ 155 (+131.34%)
Mutual labels:  queue, messaging

microq

Build Status Coverage Status microq analyzed by Codellama.io

Microq is a simple but reliable message queue built on mongodb.

Installation

$ npm install microq

Notice microq needs async/await support. So use node.js 8.x please

Usage

Adding a job

const microq = require('microq');
const queue = microq(connectionUrl);

const job = await queue.enqueue('foo', { data: 'hello' });

Starting workers

const microq = require('microq');
const queue = microq(connectionUrl);

queue.start({
  foo(params, job) => {
    // Work on job data passed in params ({ data: 'hello' })
    // To fail, throw an error
    // To succeed return something, even undefined is accepted:)
  }
}, { interval: 500 });

Notice microq uses the debug (https://www.npmjs.com/package/debug) with prefix microq. So if you need some log output turn debug on.

Writing a worker

Microq supports workers to use async/await or to return Promises. A worker may throw an exception to fail. The queue will NOT shut down if a worker fails.

Worker function should return a promise or should be defined as async functions.

async foo(params, job) => {
  await something();

  await somthingOther();

  // ...
  return;
}

In case the worker queue is started with option parallel set to false this allows the worker queue to wait until the job finishes and to set the status of the job correctly.

API

microq(connectionUrl, [options])

Creates a new queue connected to a mongodb database specified by connectionUrl. You can optionally pass connection options to mongodb.

queue.enqueue(jobName, [params], [options])

Enqueues a job with name jobName and optional params passed to the worker.

Options

  • priority - defines the dequeue priority. jobs with higher priority are dequeued first.

Returns a promise resolving to the persisted job

queue.start(workers, options)

Starts the queue with workers passed in the workers object. A worker must be a function.

Options

  • recover (Boolean) - Defines if jobs that are in status dequeued should be recovered when starting the queue. Defaults to true.
  • interval (number in milliseconds) - Defines the poll interval. Defaults to 5000 ms.
  • parallel (Boolean) - Defines whether jobs are executed in parallel. Defaults to true.

queue.query(status)

Query the queue for jobs with the given status. Status must be one of enqueued, dequeued, completed, failed.

Returns a promise resolving to a list of jobs

queue.recover()

Updates all jobs currently in dequeue status to enqueued status and adds a date field recoveredAt

queue.cleanup([date])

Removes all jobs before a specified date (new Date() if not given) in status completed or failed.

queue.stop()

Stops polling. No workers are started after stopping the queue.

Events

The queue object returned by microq(connectionUrl) is an EventEmitter emitting events:

  • failed - A worker failed to process a job
  • completed - A woker processed a job successfully
  • empty - The job queue is currently empty
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].