2.3.0 • Published 2 years ago

rabbit-on-memory v2.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Rabbit on memory

Tests

This is a module to implement a basic RabbitMQ system on memory. It allows you to implement DDD in your NodeJS application without deploying extra infrastructure.

With this module you can create exchanges, queues, bind this queues to his exchanges, publish and consume messages, etc. The allowed exchange types are: direct, topic and fanout.

Documentation

  1. Installation
  2. Singleton v/s multiple instances
  3. Options
  4. Quick examples

Installation

# NPM
npm install --save rabbit-on-memory

# Yarn
yarn add rabbit-on-memory

Singleton vs multiple instances

You can run in singleton mode or multiple instances.

// Singleton mode
import RabbitOnMemory from 'rabbit-on-memory';

// The imported object is a singleton instance. It allows you to call directly the methods:
RabbitOnMemory.setConfig(/* ... */);
RabbitOnMemory.publish(/* ... */);
RabbitOnMemory.subscribe(/* ... */);

// But if you want a new instance, you can do it:
const eventBus = RabbitOnMemory.init()
eventBus.setConfig(/* ... */);
eventBus.publish(/* ... */);
eventBus.subscribe(/* ... */);

Options

You can personalize some behaviours for this module using the method setConfig().

import RabbitOnMemory from 'rabbit-on-memory'

// To run the subscribers methods in sync mode
RabbitOnMemory.setConfig({
    syncMode: true // default: false
})

// To propagate exceptions from subscribers and stop the
// execution of the rest of them (only in sync mode)
RabbitOnMemory.setConfig({
    propagateExceptionsOnSyncMode: true // default: false
})

// To activate the debug mode
RabbitOnMemory.setConfig({
    debug: true // default: false
})

Quick examples

Creating a queue and bind to a route on an exchange

import RabbitOnMemory from 'rabbit-on-memory'

const exchange = 'exchange_name'
const exchangeType = 'direct'
const bindRoute = 'core.user.1.event.user.created'
const queue = 'send_email_on_created_user'
const callback = async (msg) => {}

RabbitOnMemory.subscribe(exchange, exchangeType, queue, bindRoute, callback)

/* This will create the exchange if not exists and will
 * create the queue binded to the exchange with the provided
 * bindRoute
*/

Publish message to a route and exchange

import RabbitOnMemory from 'rabbit-on-memory'

const exchange = 'exchange_name'
const route = 'core.user.1.event.user.created'
const msg = {
  content: userData
}

await RabbitOnMemory.publish(exchange, route, content)

/*
 * This will publish that content on the queue of that exchange
 * If this exchange not exists, it will throw an error
 */

Disclaimer

View LICENSE file for the software contained in this image.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

2.3.0

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

1.9.0

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

2.0.0

2 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

0.23.0

3 years ago

0.22.0

3 years ago

0.21.0

3 years ago

0.16.0

3 years ago

0.15.1

3 years ago

0.14.0

3 years ago

0.13.0

3 years ago

0.12.0

3 years ago

0.10.0

3 years ago