Skip to content

Instantly share code, notes, and snippets.

@BransonGitomeh
Created January 28, 2018 07:12
Show Gist options
  • Select an option

  • Save BransonGitomeh/783b156ed96b7a2e9ae214f90d4fa656 to your computer and use it in GitHub Desktop.

Select an option

Save BransonGitomeh/783b156ed96b7a2e9ae214f90d4fa656 to your computer and use it in GitHub Desktop.
seneca microservices and clients talking to each other in a mesh fassion,
var seneca = require('seneca')
seneca()
// send matching actions out over the network
.client({
host: "localhost",
type: 'tcp',
port: 10000,
pin: 'color:blue'
})
.client({
host: "localhost",
type: 'tcp',
port: 20000,
pin: 'color:red'
})
.act('color:red')
.act('color:blue')
{
"dependencies": {
"seneca": "^3.4.3"
},
"scripts": {
"start": "node client.js & node app2.js & node app1.js"
}
}
function color() {
this.add('color:red', function (args, done) {
console.log("acting red")
done(null, {
hex: '#red'
});
})
}
var seneca = require('seneca')
seneca()
.use(color)
.listen({
type: 'tcp',
port: "20000"
})
function color() {
this.add('color:blue', function (args, done) {
console.log("acting blue")
done(null, {
hex: 'blue'
});
})
}
var seneca = require('seneca')
seneca()
.use(color)
.listen({
type: 'tcp',
port: "10000"
})
@BransonGitomeh
Copy link
Author

BransonGitomeh commented Jan 28, 2018

todo: use redis for the transport rather than having to mention ports to connect to, broadcast the messages on redis and let the pattern matching in seneca find the correct services, that way its easier to add new services, and to use docker t deploy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment