Code Monkey home page Code Monkey logo

servicebus-retry's Introduction

servicebus-retry

servicebus-retry adds message acknowledge, reject, and retry capability to servicebus messages. A MemoryStore is available for testing and scenarios where processes to not exit/restart when a message is rejected. A RedisStore is available for multiprocess and crash-oriented design, where processes purposefully crash after a message reject and restart.

Configuration:

MemoryStore

const config = require('cconfig')();
const servicebus = require('servicebus');
const retry = require('servicebus-retry');

const bus = servicebus.bus({
  url: config.RABBITMQ_URL
});

bus.use(retry({
  store: new retry.MemoryStore()
}));

module.exports = bus;

RedisStore

const config = require('cconfig')();
const servicebus = require('servicebus');
const retry = require('servicebus-retry');

const bus = servicebus.bus({
  url: config.RABBITMQ_URL
});

bus.use(retry({
  store: new retry.RedisStore({
    host: config.REDIS.HOST,
    port: config.REDIS.PORT
  })
}));

module.exports = bus;

message.handle

servicebus-retry causes inocoming messages to have a .handle property with three available functions: acknowledge(fn), ack(fn) (shorthand for acknowledge), and reject(fn). The callback parameter in all methods is optional.

usage

bus.listen('queue.name', { ack: true /* making this queue and messages persistent */ }, function (msg) {
  msg.handle.ack(function () {
    console.log('acked message ' + msg.cid);
  });
});

bus.subscribe('routing.key2', { ack: true /* making this queue and messages persistent */ }, function (msg) {
  msg.handle.reject(function () {
    throw new Error('message ' + msg.cid + ' was rejected. let's crash and retry');
  });
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.