Created
May 3, 2017 15:11
-
-
Save dasheck0/4afda7d7fdb0d5e072a20105c4bf78cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by s.neidig on 03/05/17. | |
*/ | |
const Hemera = require('nats-hemera'); | |
const nats = require('nats'); | |
const HemeraJoi = require('hemera-joi'); | |
const config = { | |
nats: { | |
url: "nats://nats", | |
port: 4222 | |
} | |
}; | |
const connection = nats.connect(`${config.nats.url}:${config.nats.port}`); | |
const hemera = new Hemera(connection, { | |
logLevel: 'debug', | |
crashOnFatal: false | |
}); | |
hemera.use(HemeraJoi); | |
hemera.ready(() => { | |
hemera.add({ | |
topic: 'server1', | |
cmd: 'state' | |
}, (req, next) => { | |
hemera.act({ | |
topic: 'server2', | |
cmd: 'state' | |
}, (error, response) => { | |
console.log(error, response); | |
}); | |
next(null, {}); | |
}); | |
}); | |
module.exports = hemera; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "appcom-hemera-test", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "mocha --recursive test" | |
}, | |
"author": "Stefan Neidig", | |
"license": "ISC", | |
"dependencies": { | |
"chai": "^3.5.0", | |
"hemera-joi": "^1.0.2", | |
"hemera-testsuite": "^1.1.3", | |
"mocka": "0.0.1", | |
"nats": "^0.7.16", | |
"nats-hemera": "^1.1.0", | |
"sinon": "^2.2.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by s.neidig on 03/05/17. | |
*/ | |
process.env.NODE_ENV = 'test'; | |
const expect = require('chai').expect; | |
const ActStub = require('hemera-testsuite/actStub'); | |
const hemera = require('../index'); | |
describe('sever1:state', () => { | |
it('should work', (done) => { | |
const actStub = new ActStub(hemera); | |
actStub.stub({ topic: 'server2', cmd: 'state' }, null, { state: 'oke' }); // When commenting this everything works | |
hemera.act({ | |
topic: 'server1', | |
cmd: 'state' | |
}, (error, response) => { | |
expect(error).to.not.exist; | |
console.log("Act", actStub.called); | |
actStub.restore(); | |
done(); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment