Created
October 28, 2018 12:29
-
-
Save icebob/057e97d7dcc76eef312476f9338e243f to your computer and use it in GitHub Desktop.
moleculer-demo created by icebob - https://repl.it/@icebob/moleculer-demo
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
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(); | |
})(); |
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
{ | |
"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