Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dpc

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dpc

Distributed Procedure Calls using AMQP

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Distributed Procedure Calls using AMQP

Travis Codacy Badge Known Vulnerabilities Coverage Status Greenkeeper badge js-standard-style

This library provides a super easy way to declare and call remote functions from your services. You can run a single instance or scale to thousands. It's up to you!

Do you want to use callbacks, promises or async/await? All covered!

Instances do not need to be aware of each other's existence. The first instance that is available to pick up the function call, will process it, and send back the results. This way, remote procedure calls (rpc) will be handled in a distributed system: distributed procedure calls (dpc).

Requirements

Message Broker

The library uses AMQP to setup communication between the instances. You need to have a compatible message broker available like RabbitMQ.

The fastest way to get started is by signing up for a service that hosts RabbitMQ for you, like CloudAMQP. No configuration needed, and with the free plan, you get plenty for free.

Alternatively, you can install RabbitMQ on you local machine. Refer to "Downloading and Installing RabbitMQ" for the different installation methods depending on your environment.

Installation

npm i dpc

Usage

This is a full example on how to use the library to connect to a broker, register a function, and execute this function.

If you only run a single instance of this snippet, the function will actually be executed on the same instance that was calling the function. When multiple versions of this snippet are running, any of the attached instances could execute the function.

const DPC = require('dpc')

// create a new dpc instance
const dpc = new DPC()
// connect to the broker
dpc.connect({ url: 'amqp://guest:guest@localhost:5672' }).then(() => {
  // create the function that we want to execute remotely
  function sumNumbers (params, cb) {
    const numbers = params.numbers || []
    const res = numbers.reduce((a, b) => a + b, 0)
    return cb(null, res)
  }
  // register this function with dpc
  dpc.register(sumNumbers)
  // execute the function through dpc
  dpc.functions.sumNumbers({ numbers: [1, 2, 3] }, function (err, res) {
    if (err) { return console.error(err) }
    console.log(`sumNumbers: ${res}`)
  })
}).catch(err => {
  // something went wrong
  console.log(err)
})

API

See the API.md file for details.

Maintainers

Osmond van Hemert Github Web

Contributing

If you would like to help out with some code, check the details.

Not a coder, but still want to support? Have a look at the options available to donate.

License

MIT

Keywords

FAQs

Package last updated on 04 Aug 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