Socket
Socket
Sign inDemoInstall

rmq-rpc

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rmq-rpc

Simple RPC for RabbitMQ


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

RMQ-RPC

Simple, lightweight RPC calls with RabbitMQ and Node.js based on amqplib.

The RmqRpc class features an easy API for the producer and consumer of the RPC call.

Installation and quickstart

npm install rmq-rpc

Require the module:

const RmqRpc = require('rmq-rpc');

Implement the consumer (server):


    const mq = new RmqRpc(`amqp://user:password@host`);

    // Create connection and channel
    await mq.init();
    
    // Initialize an exchange and queue 'square'
    await mq.setupQueue('square');
    
    // Wait for requests
    mq.listenForMessages(async (request) => {
        // Handle request
        return Math.pow(Number(request), 2);
    }).then(() => {
        console.log('Server ready.')
    });

Implement the producer (client):

    const num = Math.random();

    const mq = new RmqRpc(`amqp://${user}:${password}@localhost`);

    // Create connection and channel
    await mq.init();

    // Send request and await result
    const result = await mq.sendRpc('square', num);

    console.log(`Num: ${num}, Square: ${result}`);

Keywords

FAQs

Package last updated on 04 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc