Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/1602/queue-commander
Simplified interface for amqp
https://github.com/1602/queue-commander
Last synced: about 1 month ago
JSON representation
Simplified interface for amqp
- Host: GitHub
- URL: https://github.com/1602/queue-commander
- Owner: 1602
- License: mit
- Created: 2015-07-07T22:30:58.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-27T13:05:42.000Z (over 8 years ago)
- Last Synced: 2024-04-14T09:15:40.959Z (7 months ago)
- Language: JavaScript
- Size: 26.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Queue Commander
AMQP for dummies
```shell
npm install queue-commander
```## Usage
```javascript
var QueueCommander = require('queue-commander');
var qc = new QueueCommander(settings());function settings() {
return {
consumeJobResults: false, // default: true
prefix: 'staging_', // prepend queue with prefix
};
}
```1. declare queue (queue-schema.js)
```
qc.registerQueue('fruits', {durable: false}); // configure queue here
```2. declare channel(s) (queue-schema.js)
```javascript
var apple = qc.channel({name: 'apple', input: 'fruits'}); // RPC
var orange = qc.channel({name: 'orange', input: 'fruits', output: 'results'}); // remote job
```3. on server (server.js)
```javascript
apple.onServer(function(args, done, ack) {
ack(true);
setTimeout(function() {
done(null, 'yummy ' + args.name);
}, 1000);
});
```4. on client: remote call (client-rpc.js)
```javascript
// register call
var sendToAppleQueue = apple.onClient();
// make a call
sendToAppleQueue({name: 'golden apple'}).then(function(response) {
console.log(response); // yummy golden apple
});
```5. on client: remote job (client-job.js)
```javascript
// register job
var sendToOrangeQueue = orange.onClient(function(err, res, next){
console.log(res); // yummy sweet orange
next();
});
// post a job
sendToOrangeQueue({name: 'sweet orange'}); // note that callback will not be called
```