Skip to content

Instantly share code, notes, and snippets.

@icebob
Created October 28, 2018 12:29
Show Gist options
  • Save icebob/057e97d7dcc76eef312476f9338e243f to your computer and use it in GitHub Desktop.
Save icebob/057e97d7dcc76eef312476f9338e243f to your computer and use it in GitHub Desktop.
moleculer-demo created by icebob - https://repl.it/@icebob/moleculer-demo
const { ServiceBroker } = require('moleculer');
let broker = new ServiceBroker({
logger: console,
logLevel: 'info',
transporter: "nats://demo.nats.io:4222"
});
broker.createService({
name: 'math',
actions: {
add(ctx) {
return Number(ctx.params.a) + Number(ctx.params.b);
}
}
});
(async function() {
await broker.start();
// Call service
const res = await broker.call('math.add', { a: 5, b: 3 });
console.log('5 + 3 =', res);
broker.repl();
})();
{
"main": "index.js",
"dependencies": {
"moleculer": "0.13.2",
"moleculer-repl": "0.5.2",
"nats": "1.0.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment