an open-source package to make it easy and simple to work with RabbitMQ's RPC ( Remote Procedure Call )

Overview

RabbitMQ Easy RPC (Remote Procedure Call )

The Node.js's RabbitMQ Easy RPC Library

download-image

Ali-A-Koye - rabbitmq-easy-rpc License

rabbitmq-easy-RPC is an easy to use npm package for rabbitMQ's RPC functionality. This package tries to make the developer's life easier by providing a wrapper around the rabbitMQ's RPC functionality so it is easier to use.

RabbitMQ's RPC and what does this package try to solve?

In distributed computing, a remote procedure call is when a computer program causes a procedure to execute in a different address space, which is coded as if it were a normal procedure call, without the programmer explicitly coding the details for the remote interaction. RabbitMQ, as one of the message-broker software, supports this functionality of RPC call, you can read it from the official documentation here. However, this functionality has been achieved by using queues and the problem here is that it's harder to code a producer and a listener for the response.

With this package, it is done for you to just send your message and "await" it with asynchronous programming, and the queue management and listeners are handled by the package.

Key Features

  • Easy to use.
  • it accepts RabbitMQ's as a parameter, thus you have the flexibility to do your RabbitMQ's channel reusability management.
  • Queue Management is handled by the package itself. It will create the necessary queues in the background without any interaction.
  • creates and destroys consumers for replies and requests.
  • Package built with Typescript, you will get the Typescript benefits of validation of your data if you already use Typescript.

Table of Contents

Demo

This is a simple Demo environment for the package where you can use and test the package , in the demo folder, there are 2 folders called A and B which represent Microservice A and Microservice B and the package is integrated with both of them so they can communicate with each other.

Work with the Demo instruction ( for each microservice )  :

npm install  // Installing dependencies
node server.js // To start the express.js server

Requirements

In order to work with this package, you are required to have :

  • install node.js and npm
  • RabbitMQ server running locally or on the cloud

Installation

To use the package you must first add it to your dependencies in your project.

$ npm i rabbitmq-easy-rpc

Then you have to register the package for your project.

Typescript

import rabbitmqEasyRpc from "rabbitmq-easy-rpc";

Javascript

const rabbitmqEasyRpc = require("rabbitmq-easy-rpc");

Usage

The package consists of two functions that operate two major functions ( Listening and Requesting ). We will explain the necessary steps and tutorials for this package below.

With our aim for simplicity of this package, the integration part is the easiest and we will demonstrate it below.  

1 - Listening to incoming messages from others

You need this functionality only if you expect that you might get an RPC call from another place and your microservice has to respond. In that case, you must call this function with the server starting so it will establish a queue and a consumer to be ready for incoming messages.  

  • The first parameter is the rabbitMQ's channel, which should be used to receive incoming messages. You can reuse your channels and pass any channel you want.
  • The callback is an asynchronous function that you pass. It will give you the incoming data and you can do any operations on it ( remember its passed by reference, so your changes are reflected ) and at the end, it just responds with the changed data.
  • The last one is the source name. It's your tag to communicate with other places and you will receive messages with this tag.
rabbitmqEasyRpc.listen({
    channel,
    callback: async (data) => {
      //any logic you want to do before sending back to the requester
      console.log(data);
    },
    source: "origin_name",
  });

2 - requesting or sending data to other places and wait for their response.

You need this functionality to communicate with the other microservices. Maybe your microservice depends on another microservice, so it has to wait for the response to proceed.

  • to : the destination you want to hit with your message. Remember you have to put the source name's value of the destination , it has to be the same to hit
  • data : You have to pass a string in any case because any other type will throw an error because rabbitMQ only works with buffers.
  • channel: channel you want this call to use and perform communication.
  let response = await rabbitmqEasyRpc.request({
    to: "other_microservice_label",
    data: JSON.stringify({  
      dummy: "data1",
    }),
    channel,
  });

How Does it Work?

So, by focusing on the bigger image, this package helps you to send or receive messages from one place to another, preferably with a microservice architecture. 
This package uses temporary queues and consumers send a request and wait for the reply. The queues will get deleted as well as the consumers right after we get the response.
Also, the packages use one permanent queue for listening per microservice.

So every microservice is labeled with a name. This name can be used to communicate with each other through listen and request functions. It's as simple as that.

API

Below is a table of acceptable parameters for this library.

Listen :

Parameter Description Default Validations
Channel RabbitMQ's Channel   Required
Callback Function that handles the data before sending it back to the requester   Required
source label or tag for your section   required

Request

Parameter Description Default Validations
to destination microservice   Required
data stringify version of your data to be passed   Required
Channel RabbitMQ's Channel   Required

Author

Ali Amjed

License

The MIT License

You might also like...

Open source packages to work with fogbender.com

Fogbender Open-Source Software Open source packages to work with https://fogbender.com What is Fogbender? Fogbender is a helpdesk product for supporti

Jan 8, 2023

Create a 3D interactive object using images and one simple JS call

#Interactive 3D by Pete R. Create a 3D interactive object using images and one simple JS call Created by Pete R., Founder of BucketListly Demo View de

Nov 17, 2022

Interactive 3D plotting with a simple function call using Three.js

Interactive 3D plotting with a simple function call using Three.js

About Generate interactive 3d plots with a simple function call. Function returns a Three.js scene which can be customized as needed. Basic function c

Oct 20, 2022

This project is for hacktoberfest to encourage new developer and open source developers to contribute to open source and improve skills which require debugging, write testable code, industry standards, problem solving and many more,

This project is for hacktoberfest to encourage new developer and open source developers to contribute to open source and improve skills which require debugging, write testable code, industry standards, problem solving and many more,

🚀 Blog project for hacktoberfest In this repository, you can find issues related to a blog project that is built on top of Next.js. The project is a

Oct 9, 2022

RPC-like client, contract, and server implementation for a pure REST API

RPC-like client, contract, and server implementation for a pure REST API

ts-rest RPC-like client and server helpers for a magical end to end typed experience Introduction ts-rest provides an RPC-like client side interface o

Dec 30, 2022

A MITM cache between RPCs and a a dAPP. Useful to allow for better performance on a public RPC node

better-cosmos-rpcs A cheaper way to allow for public RPCs as a service WITHOUT scaling issues. No need to rate limit either. How it is done: User GET

Nov 19, 2022

An interactive Bitcoin tutorial for orange-pilled beginners. Illustrates technical Bitcoin concepts using JavaScript and some Bitcoin Core RPC commands. Programming experience is helpful, but not required.

An interactive Bitcoin tutorial for orange-pilled beginners. Illustrates technical Bitcoin concepts using JavaScript and some Bitcoin Core RPC commands. Programming experience is helpful, but not required.

Try Bitcoin Try Bitcoin is an interactive Bitcoin tutorial inspired by and forked from Try Regex, which is inspired by Try Ruby and Try Haskell. It il

Nov 25, 2022

Collection of JSON-RPC APIs provided by Ethereum 1.0 clients

Ethereum JSON-RPC Specification View the spec The Ethereum JSON-RPC is a collection of methods that all clients implement. This interface allows downs

Jan 8, 2023

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols.

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols.

OCPP-RPC A client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protcols (e.g. OCPP1.6J and OCPP2.0.1J). Re

Dec 30, 2022
Owner
Ali Amjad
Software Engineer | Full Stack Developer | Professional Back-End Developer | Problem Solver
Ali Amjad
⚡🚀 Call multiple view functions, from multiple Smart Contracts, in a single RPC query!

ethers-multicall ⚡ ?? Call multiple view functions, from multiple Smart Contracts, in a single RPC query! Querying an RPC endpoint can be very costly

Morpho Labs 20 Dec 30, 2022
fcall, fetch and call any remote hot functions, anywhere, anytime, without installations or configurations.

fcall, fetch and call any remote hot functions, anywhere, anytime, without installations or configurations.

立党 Lidang 4 Sep 20, 2022
A JavaScript Library To Make Your Work Work Easier/Faster

Functionalty.js (beta) About ✍️ This Is A JavaScript Library To Make Your Work Easier/Faster, You Can See Functionalty.js Website From Here Project Cr

Ali-Eldeba 16 Aug 30, 2022
A JavaScript Library To Make Your Work Work Easier/Faster

Functionality.js (beta) About ✍️ This Is A JavaScript Library To Make Your Work Easier/Faster, You Can See Functionalty.js Website From Here Project C

Ali-Eldeba 9 May 25, 2022
A JavaScript Library To Make Your Work Work Easier/Faster

Functionality.js About ✍️ This Is A JavaScript Library To Make Your Work Easier/Faster, You Can See Functionalty.js Website From Here Project Created

functionality 16 Jun 23, 2022
open-source implementation of the Turborepo custom remote cache server.

This project is an open-source implementation of the Turborepo custom remote cache server. If Vercel's official cache server isn't a viable option, th

Maksim Sinik 362 Dec 30, 2022
Open source project that make it easy to sync your calendars in real time.

Syncit 2.0 - We make it easy to sync your calendars in real time. This is an Open source project! Installation Run yarn in order to install all depend

Tikal Knowledge, Ltd. 6 Dec 15, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
🏆Open source, free project management/issue tracking software to manage your work and projects

WorkClever ?? Open source, free project management/issue tracking software to manage your work and projects Features General Free to use, open source

WorkClever 11 Dec 27, 2022
A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fast, stores the Cache before stopping and restores it again!

remote-map-cache A remote nodejs Cache Server, for you to have your perfect MAP Cache Saved and useable remotely. Easy Server and Client Creations, fa

Tomato6966 8 Oct 31, 2022