npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongo-to-rabbit

v4.0.5

Published

a mongodb watcher notifying rabbitmq

Downloads

21

Readme

mongo-to-rabbit v4.0.1

npm NPM Snyk Vulnerabilities for npm package npm

An npm package designed for listening to MongoDB and notifying a RabbitMQ server on changes.

MTR logo

Using MenashMQ for connection to RabbitMQ.

Installation

  1. npm i --save mongo-to-rabbit

In order to use the package, you must send two object parameters:

1- Rabbit Data:

contains 2 fields: | # | field | type | info | default | |---|---|---|---|---| | 1 | queues | QueueObjectType | array of destination queues names to send the information to and the middlewareFunc| | 2 | rabbitURI | string | the connection string for the rabbitMQ server | | 3 | healthCheckInterval? | number | the health check interval for rabbit |30000 ms| | 4 | rabbitRetries? | number | amount of retries to connect to rabbit |5|

2- Mongo Data:

contains 2 fields: | # | field | type | info | default | |---|---|---|---|---| | 1 | collectionName | string | the name of the mongo collection you want to listen to | | 2 | connectionString | string | the connection string of the mongo server | | 3 | healthCheckInterval? | number | the health check interval for mongo | 30000 ms|

MTROptions - optional:

contains 3 fields: | # | field | type | info | default | |---|---|---|---|---| | 1 | silent | boolean | if false, logs connection and changes to the console | true | | 2 | prettify | boolean | if true, will filter the result and send it in a specific format | true|

Types:

| # | field | type | info | default | |---|---|---|---|---| | 1 | QueueObjectType | name: string, middleware?: MiddlewareFuncType exchange?: ExchangeObjectType | queue name, middleware parser and exchange | - | | 2 | MiddlewareFuncType | (DataObjectType, collectionName) => (null | string | Object | Buffer | string[] | Object[] | Buffer[] | undefined) | A function for manipulating the prettified data received from the listener before sending it to the queue. will only work with a prettify:true. | identity function | | 3 | ExchangeObjectType | name: string, type: ExchangeType, routingKey?: string | exchange implementation | - | | 4 | ExchangeType | fanout, topic, direct, headers | different types of exchanges, read more at - exchange types | - |


Example:

import { watchAndNotify } from 'mongo-to-rabbit';

let rabbitData = {
  queues: [{ name: 'MyQueueName' }],
  rabbitURI: 'amqp://localhost',
};

let mongoData = {
  collectionName: 'files',
  connectionString: 'mongodb://localhost:27017/devDB?replicaSet=rs0',
};

watchAndNotify(mongoData, rabbitData);
  • For a more specific example, look at the src/example folder.

The prettified type format:

type DataObjectType = {
  id: string,
  operation: string,
  fullDocument: object,
  updateDescription: {
    updatedFields: object,
    removedFields: string[],
  },
};
  • prettify will only work on operations related to documents in the collection: insert, replace, update, delete

To run the package locally with the example:

  1. run rabbit locally: docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management
  2. Initiate the mongo replica: sudo mongod --replSet rs0
  3. npm run connect
  4. npm run receive
  5. mongo
  6. >use devDB
  7. db.files.insertOne({ "name": "it works!"})
  • The connect script connects with two different configurations to mongo and rabbit.
  • The receive script creates two consumers to Rabbit.
  • If succeeded, you should see the result sent at the console.log of the receiver.

running example

logo credit: Vector image by VectorStock / ade01