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

rabbitmq-client-wrapper

v1.0.0

Published

[![Code style: airbnb](https://img.shields.io/badge/code%20style-airbnb-blue.svg?style=flat-square)](https://github.com/airbnb/javascript) ![node (scoped with tag)](https://img.shields.io/node/v/@stdlib/stdlib/latest.svg)

Downloads

3

Readme

rabbitmq-client-wrapper

Code style: airbnb node (scoped with tag)

Rabbitmq Client Wrapper The tool you can send/consume messages throw RabbitMQ. That is created in base of amqpjs which is an architectural pattern for message validation, transformation, and routing. It mediates communication among applications, minimizing the mutual awareness that micro-services should have of each other in order to be able to exchange messages.


Installation

  • You can find in a config folder a file containing the default properties of queue
  • You have a option to setup your enviroment with dotenv
  git clone https://github.com/cdjohnnatha/rabbitmq-client-wrapper.git

How it Works!

Take a look that you have basically two important functions which is Sender and Consume. Sender you can send message throw RabbitMQ using a method called sendToQueue where you must use a function from Consume called consumefromQueue.

The tool was implemented using an idea of in and out queues, so is required identify in the begin of queue if the queue is 'input-' or 'output-', for example: input-myQueue, output-myQueue (the pattern of 'input-' and 'output-' can be changed in .env file).

Sender

The send have just one approach:

  • To send a message throw RabbitMQ is required send an id which will identify who or for who will be send a message, the queue name which identify which queue will be used and the message.

Example:

const queueSender = require('./lib/queueSender');
...

queueSender.sendToQueue('my-message-id', 'input-service', 'my message');

// The same approach is used to send a message for an output-queue
queueSender.sendToQueue('my-message-id', 'output-service', 'my message');

Consume

The consume have two approaches:

  • The service which read from an input- queue is unnecessary know who send it, so any service which is connected to that input- queue can consume the message using the callback function.

Example

try{
    // service which consume from input-queue
    queueConsume.consumeFromQueue('', 'input-service', (error, ch, msg, timeoutService) => {
      // Build a message.
      const message = BuildMessageBody(msg);
      // code...
      // Identify that the process worked successfully.
      ConsumedSignal(ch, msg, timeoutService);
    });
  } catch (error) {
    console.log(error);
  }
  • The service which will consume from output- MUST IDENTIFY THE ID to get the properly message.
try{
    // service which consume from input-queue
    queueConsume.consumeFromQueue('my-message-id', 'output-service', (error, ch, msg, timeoutService) => {
      // Build a message.
      const message = BuildMessageBody(msg);
      // code...
      // Identify that the process worked successfully.
      ConsumedSignal(ch, msg, timeoutService);
    });
  } catch (error) {
    console.log(error);
  }

Features

  • Sender message to queue
  • Consume message to queue
  • Functions Helper (queueHelper, messageHelper, inputHelper)

Security Issues

If you discover a security vulnerability in rabbitmq-client-wrapper, contact-me.

Dependências

  • amqplib

  • If you are using the dotenv it is necessary write variables in your dotenv file as below:

    • AMQP_HOST
    • DEFAULT_HOST
    • QUEUE_MESSAGE_EXPIRATION_TIME
    • AMQP_HOST
    • INPUT_QUEUE_PATTERN
    • OUTPUT_QUEUE_PATTERN
    • QUEUE_ARGS_DURABLE
    • QUEUE_ARGS_EXCLUSIVE
    • QUEUE_ARGS_EXPIRATION_TIME
    • NO_ACK_ARG=false

Testes

Dependency
  • mochajs

  • gulp

  • gulp-mocha

    • To test the queue enviroment which have an example of an airport where simulate some services such as check_in, check_out, luggage_in, luggage_out and some clients.
  npm install
  gulp mocha

Samples

At tests/samples you can find the examples used at crossingProcesses test which use both libs, queue_sender and queue_consume.


Example:

OBS: Must be String to send a message for queue.

const queueConsume = require('./lib/queueConsume');
const queueSender = require('./lib/queueSender');

const { BuildMessageBody } = require('./helpers/messageHelper');
const { ConsumedSignal } = require('./helpers/queueHelper');

// service sending object (as string), string...
queueSender.sendToQueue('some-id', 'input-service', 'my message');
// service waiting processed informations from out 
queueConsume.consumeFromQueue('some-id', `output-service`, (error, ch, msg, timeout) => {
  const message = BuildMessageBody(msg);
  // code...
  ConsumedSignal(ch, msg, timeout);
});

try{
    // service which consume from input-queue
    queueConsume.consumeFromQueue('', 'input-service', (error, ch, msg, timeoutService) => {
      const message = BuildMessageBody(msg);
      // code...
      // service which send processed object to out service which will be consumed by 
      // output-queue
      queueSender.sendToQueue(String(message.id), 'output-service', 'My service object');
      ConsumedSignal(ch, msg, timeoutService);
    });
  } catch (error) {
    console.log(error);
  }

Contributor

Claudio Djohnnatha Duarte Lourenço (cdjohnnatha) [email protected]