# dpc

> Distributed Procedure Calls using AMQP

Latest version **1.0.5** (published 2019-08-04) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install dpc
pnpm add dpc
yarn add dpc
bun add dpc
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2019-08-04 |
| First published | 2018-08-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.9.0 |
| Dependencies | 3 |
| Unpacked size | 32.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Osmond van Hemert |
| Maintainers | ovhemert |
| Keywords | amqp, amqplib, async, await, call, callback, distributed, functions, microservice, procedure, promise, rabbitmq, remote, rpc |

## Links

- npm: https://www.npmjs.com/package/dpc
- Repository: https://github.com/ovhemert/dpc
- Homepage: https://github.com/ovhemert/dpc#readme
- Issues: https://github.com/ovhemert/dpc/issues
- npm.io page: https://npm.io/package/dpc

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [dotenv](https://npm.io/package/dotenv.md) ^8.0.0
- [amqplib](https://npm.io/package/amqplib.md) ^0.5.5

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2019-08-04
- 1.0.4 — 2019-05-27
- 1.0.3 — 2019-04-27
- 1.0.2 — 2019-02-28
- 1.0.1 — 2018-08-27
- 0.1.1 — 2018-08-24
- 0.0.6 — 2018-08-13
- 0.0.5 — 2018-08-10
- 0.0.4 — 2018-08-10
- 0.0.3 — 2018-08-10
- 0.0.2 — 2018-08-10

## README

# Distributed Procedure Calls using AMQP

[![Travis](https://img.shields.io/travis/com/ovhemert/dpc.svg?branch=master&logo=travis)](https://travis-ci.com/ovhemert/dpc)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/6c7db239873b4d1eaa4f7e268aadccff)](https://www.codacy.com/app/ovhemert/dpc?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=ovhemert/dpc&amp;utm_campaign=Badge_Grade)
[![Known Vulnerabilities](https://snyk.io/test/npm/dpc/badge.svg)](https://snyk.io/test/npm/dpc)
[![Coverage Status](https://coveralls.io/repos/github/ovhemert/dpc/badge.svg?branch=master)](https://coveralls.io/github/ovhemert/dpc?branch=master)
[![Greenkeeper badge](https://badges.greenkeeper.io/ovhemert/dpc.svg)](https://greenkeeper.io/)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)

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](https://www.rabbitmq.com).

The fastest way to get started is by signing up for a service that hosts RabbitMQ for you, like [CloudAMQP](https://www.cloudamqp.com). 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](https://www.rabbitmq.com/download.html)" for the different installation methods depending on your environment.

## Installation

```sh
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.

```js
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](./docs/API.md) file for details.

## Maintainers

Osmond van Hemert
[![Github](https://img.shields.io/badge/-website.svg?style=social&logoColor=333&logo=github)](https://github.com/ovhemert)
[![Web](https://img.shields.io/badge/-website.svg?style=social&logoColor=333&logo=nextdoor)](https://ovhemert.dev)

## Contributing

If you would like to help out with some code, check the [details](./docs/CONTRIBUTING.md).

Not a coder, but still want to support? Have a look at the options available to [donate](https://ovhemert.dev/donate).

## License

MIT

---
_Source: https://npm.io/package/dpc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
