Skip to content

Commit

Permalink
feat: basic cli to access rabbitmq
Browse files Browse the repository at this point in the history
  • Loading branch information
AVVS committed Feb 3, 2016
1 parent e2f1a46 commit 94e2b48
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [
"transform-es2015-spread",
"transform-es2015-destructuring",
"transform-strict-mode",
"transform-es2015-parameters",
"transform-es2015-shorthand-properties",
"transform-object-rest-spread",
"transform-class-properties"
]
}
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
*.md
8 changes: 8 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "airbnb/base",
"parser": "babel-eslint",
"rules": {
"prefer-arrow-callback": 0,
"max-len": [2, 150]
}
}
8 changes: 8 additions & 0 deletions bin/ms-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node

try {
require('babel-register');
require('../src/index.js');
} catch (e) {
require('../lib/index.js');
}
41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "ms-cli",
"version": "1.0.0",
"description": "cli to access microservices over amqp through command line",
"main": "./lib/index.js",
"bin": {
"ms-cli": "./bin/ms-cli.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/makeomatic/ms-cli.git"
},
"keywords": [
"microservice",
"cli"
],
"author": "Vitaly Aminev <v@makeomatic.ru>",
"license": "MIT",
"bugs": {
"url": "https://github.com/makeomatic/ms-cli/issues"
},
"homepage": "https://github.com/makeomatic/ms-cli#readme",
"dependencies": {
"bluebird": "^3.2.1",
"bunyan": "^1.5.1",
"ms-amqp-transport": "^1.3.0",
"yargs": "^3.32.0"
},
"devDependencies": {
"babel-cli": "^6.4.5",
"babel-register": "^6.4.3",
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"eslint": "^1.10.3",
"eslint-config-airbnb": "^4.0.0",
"babel-eslint": "^5.0.0-beta9"
}
}
32 changes: 32 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const Promise = require('bluebird');
const getTransport = require('./transport.js');
const bunyan = require('bunyan');
const log = bunyan.createLogger({ name: 'ms-cli' });

const yargs = require('yargs')
.usage('Usage: $0 --q.offset=0 --q.limit=10 -p payments.transactions.common -h rabbitmq -p 5672')
.alias('p', 'port')
.describe('p', 'rabbitmq port')
.default('p', 5672)
.alias('h', 'host')
.describe('h', 'rabbitmq host')
.default('h', 'localhost')
.alias('r', 'route')
.describe('r', 'rabbitmq routing key')
.demand('r')
.describe('q', 'query object')
.default('q', {})
.alias('t', 'timeout')
.describe('t', 'request timeout')
.default('t', 15000);

process.nextTick(() => {
const argv = yargs.argv;

// issue command
Promise.using(getTransport(argv.host, argv.port), amqp => (
amqp.publishAndWait(argv.route, argv.q, { timeout: argv.timeout }).then(response => {
log.info(response);
})
));
});
10 changes: 10 additions & 0 deletions src/transport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const Promise = require('bluebird');
const AMQPTransport = require('ms-amqp-transport');

module.exports = function disposer(host, port) {
return AMQPTransport
.connect({ connection: { host, port } })
.disposer(amqp => {
return amqp.close();
});
};

0 comments on commit 94e2b48

Please sign in to comment.