Installation
$ npm install @betit/orion-node-sdk
Basic example
Note - You will need to have running all of the orion dependencies
Add the following into foo.js
and then run node foo.js --verbose
const ORION = require('@betit/orion-node-sdk');
const FOO = new ORION.Service('foo');
FOO.handle('get', (req, reply) => {
reply(new ORION.Response('foo'));
});
FOO.listen(() => FOO.logger.createMessage('ready').send());
Then add the following into bar.js
and then run node bar.js
const ORION = require('@betit/orion-node-sdk');
const BAR = new ORION.Service('bar');
const REQ = new ORION.Request('/foo/get');
BAR.call(REQ, res => {
});
You can find more detailed examples in the examples
folder.
Async example
This utility also supports functionality with Promises, so the following code can be also used:
const ORION = require('@betit/orion-node-sdk');
const FOO = new ORION.Service('foo');
FOO.handle('get', async (req) => {
return new ORION.Response('foo');
});
async function initFOO() {
await FOO.listen();
FOO.logger.createMessage('ready').send()
}
init().then(exit);
And in bar.js
:
const ORION = require('@betit/orion-node-sdk');
const BAR = new ORION.Service('bar');
const REQ = new ORION.Request('/foo/get');
async function main() {
const res = await BAR.call(REQ);
}
main().then(exit);
Also, subscriptions can now be looped forever using:
const ORION = require('@betit/orion-node-sdk');
const BAR = new ORION.Service('bar');
async function processEvents() {
const producer = BAR.onAsync("event");
while (true) {
const event = await producer.consume();
}
}
...
Documentation
Auto-generated documentation is located here.
Tests
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
License
MIT