# distributor

> Easy distribution of resources through AMQP

Latest version **0.4.0** (published 2013-09-19) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 5/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2013-09-19 |
| First published | 2013-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | addisonj |
| Keywords | amqp, rabbitmq, resources |

## Links

- npm: https://www.npmjs.com/package/distributor
- Repository: https://github.com/addisonj/distributor
- npm.io page: https://npm.io/package/distributor

## Dependencies (2)

- [amqp](https://npm.io/package/amqp.md) git://github.com/postwait/node-amqp.git#bf276583
- [underscore](https://npm.io/package/underscore.md) ~1.4.4

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2013-09-19
- 0.3.1 — 2013-08-29
- 0.3.0 — 2013-08-28
- 0.2.4 — 2013-08-09
- 0.2.3 — 2013-03-19
- 0.2.2 — 2013-03-07
- 0.2.1 — 2013-03-06
- 0.2.0 — 2013-03-05
- 0.1.0 — 2013-03-02
- 0.0.0 — 2013-02-28

## README

![](https://travis-ci.org/addisonj/node-distributor.png)

## Distributor
Resource based distribution of messages

### What?
If you do SOA, you will probably get to a point where others need to be informed of changes to a certain resource. Distributor makes it easy.

### How?

```JavaScript
// producer
var Distributor = require("distributor").Distributor

var distributor = new Distributor("amqp://localhost:5672", "service_name", "exchange_name")
// or
var distributor = new Distributor({...amqp connection options...}, "service_name", "exchange_name")

postsResoutce = disributor.register("posts")
postsResource.publish({beep: "boop"})
postsResource.publish({beep: "loop"}, opts, function(err) {
})
postsResource.registerSubTopic("comments")
postsResource.publishComments({name: "Bob", message: "hi"})
// get your resources out
writeFile("resourceDefinitions.json", disributor.getDefinition())

  
// consumer

var Client = require("distributor").Client
// fetch your resource definition
var resourceDefintions = readFile("resourceDefinitions.json")

var client = new Client(resourceDefinitions)

// want a work queue?
worker = client.posts.createWorker("shared_queue_name")
worker.subscribe(function(msg, cb) { // subscribe on the default topic, or specify another topic (routing key)
  // ack when done
  cb()
})

// or pub sub instead?
worker = client.posts.createSubscriber() // doesn't take a name, exclusive queue to each client
worker.subscribe("service_name.posts.comments", function(msg, cb) {
  cb()
})

// want a global worker instead
worker = client.createSubsciber()
// subscribes to "service_name.#" by deafult
worker.subscribe(function(msg, cb) {
  cb()
})
```

### API
```JavaScript
Distributor(connectionString, serviceName, exchangeName, connectionOpts)
connectionString - either amqp connectionString (amqp://..) or an options hash to be passed to node-amqp
serviceName - the high level name for the service (used when creating the topics)
exchangeName - the name of the exchange you want to use
connectionOpts (not required) - extra options to pass to node-amqp

distributor.register resourceName, exchangeName
resourceName - the name of the resources that you want to send messages on (posts, comments, etc)
exchangeName (optional) - a different exchange to publish too
```
###
### Advanced
If you want to tweak default options/values to rabbitmq
```Javascript
var distributor = require("distributor")
distributor.defaults.publish.deliveryMode = 1


// changing ack behavior on a worker
worker.onMessage = function(userHandlerFn) {
  var self = this
  // don't require user to call back, auto ack
  return function(msg, headers, deliverInfo) {
    userHandlerFn msg
    self.queue.shift()
  }
}
```

### Defaults
Distributor defaults to reliability, which means publish and consumer confirms are enabled

### Questions? Feature Requests?
Open a pull request!

### License
MIT

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