# node_amqp_rpc

> amqp rpc promise library

Latest version **2.3.4** (published 2018-12-26) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.4 |
| Published | 2018-12-26 |
| First published | 2018-01-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 5 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Johnny Huang |
| Maintainers | johnny9144 |
| Keywords | amqp, rpc, promise, lib, rabbitMQ, rabbit, MQ, node |

## Links

- npm: https://www.npmjs.com/package/node_amqp_rpc
- Repository: https://github.com/johnny9144/amqp_rpc
- Issues: https://github.com/johnny9144/amqp_rpc/issues
- npm.io page: https://npm.io/package/node_amqp_rpc

## Dependencies (5)

- [debug](https://npm.io/package/debug.md) ^3.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [amqplib](https://npm.io/package/amqplib.md) ^0.5.2
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.1
- [node-uuid](https://npm.io/package/node-uuid.md) ^1.4.8

## Recent versions

- 2.3.4 (latest) — 2018-12-26
- 2.3.3 — 2018-09-19
- 2.3.2 — 2018-09-13
- 2.3.1 — 2018-09-11
- 2.3.0 — 2018-09-10
- 2.2.2 — 2018-06-20
- 2.2.1 — 2018-05-15
- 2.2.0 — 2018-01-26
- 2.1.0 — 2018-01-25
- 2.0.0 — 2018-01-23
- 1.0.0 — 2018-01-22

## README

# node-amqp-rpc( Promise )
![Version](http://img.shields.io/npm/v/node_amqp_rpc.svg) &nbsp;
![License](http://img.shields.io/npm/l/node_amqp_rpc.svg) &nbsp;
![Download Stats](https://img.shields.io/npm/dm/node_amqp_rpc.svg)

Library to help you use amqp RPC on easy way.

## Installation

To install randomstring, use [npm](http://github.com/npm/npm):

```
npm install node_amqp_rpc
```

## Usage
### Quick Start
```javascript
const amqp_api = require('node_amqp_rpc');
(async () => {
	const amqp = await amqp_api.quickStart( 'amqp://guest:guest@localhost:5672/');
	const queueName = 'hello.word';
	amqp.onRPC( queueName, ( data, send) => {
		console.log( data);
		// { value: 'hello world' }
		send( { value: 'consumer say hello to you' });
	});
	
	const data = { value: 'hello world' };
	const result = await amqp.callRPC( queueName, data);
	console.log( result);
	// { value: 'consumer say hello to you' }
})();

```
### producer
```javascript
const amqp_api = require('node_amqp_rpc');
(async () => {
	const amqp = new amqp_api({
		host : 'localhost',
		port : 5672,
		user : 'guest',
		password : 'guest',
		vhost : '/'
	});
	await amqp.init();
	
	const queueName = 'hello.word';
	const data = { value: 'hello world' };
	const result = await amqp.callRPC( queueName, data);
	console.log( result);
	// { value: 'consumer say hello to you' }
})();
```
### consumer

```javascript
const amqp_api = require('node_amqp_rpc');
(async () => {
	const amqp = new amqp_api({
		host : 'localhost',
		port : 5672,
		user : 'guest',
		password : 'guest',
		vhost : '/'
	});
	await amqp.init();
	
	const queueName = 'hello.word';
	amqp.onRPC( queueName, ( data, send) => {
		console.log( data);
		// { value: 'hello world' }
		send( { value: 'consumer say hello to you' });
	});
})();
```

## API

 - constructor ( Object | String )
 	- `Object`
 		- host - Your amqp server address ( Type: String || default: localhost)
    	- port - AMQP server port( Type: Integer || default: 5672 )
    	- user - The amqp account which you want to login ( Type: String )
    	- password - password ( Type: String )
    	- vhost - Virtual Hosts( Type: String || default: / )
    - `String`
    	- amqp[s]://[user:password@]hostname[:port][/vhost]
    	- ex. amqp://guest:guest@localhost:5672/
 - `init` ()
 	- Need to be execute before callRPC and onRPC
 - `callRPC` ( QueueName, Data, Timeout )
 	- `QueueName` ( String | Required )
 		- queue name  
 	- `Data` ( Object | Required )
 		- data you want to send 
 	- `Timeout` ( Integer | Option | Default: 30 )
 		- timeout seconds
 - `onRPC` ( QueueName, DoSomething )
	- `QueueName` ( String | Required )
 		- queue name
	- `DoSomething` ( Function | Required )
		- Receives the following arguments
			- data ( Object )
			- send ( Function )
 - `quickStart` ( Object | String )
   - `Object`
 		- host - Your amqp server address ( Type: String || default: localhost)
    	- port - AMQP server port( Type: Integer || default: 5672 )
    	- user - The amqp account which you want to login ( Type: String )
    	- password - password ( Type: String )
    	- vhost - Virtual Hosts( Type: String || default: / )
    - `String`
    	- amqp[s]://[user:password@]hostname[:port][/vhost]
    	- ex. amqp://guest:guest@localhost:5672/
 - `callPublish` ( exchange, routingKey, Data)
 	- `exchange` ( String | Required )
 	- `routingKey` ( String | Required )
 	- `Data` ( Object | Required )
 		- data you want to send 
 - `close` ()
 	- Close amqp connection
	
## HISTORY
- v1.0.0
	- Publish.
- v2.0.0
	- Turn library in to ES6 Classes. 
	- Connection config field 'pass' rename to 'password'.
	- Set default value for field ( host, port ).
- v2.1.0
	- Add quickStart method.
	- Add connection close method.
	- accept amqp url to start connection.
- v2.2.0
	- Support multi connection 
- v2.3.0
	- Add callPublish method.

## LICENSE

node\_amqp\_rpc is licensed under the MIT license.

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