senecaService.js
const Seneca=require('seneca-await');
const seneca = Seneca();
seneca
.listen({port: 10, pin: {role: 'test'}})
.ready(function(){
console.log("微服务启动")
});
seneca.add({
role:"test", //添加监听,可以自定义字段做监听
cmd:"sayhello",
},async function(msg) {
//一些操作
// console.log(msg)
return {name:"chen"};
})
senecaClient.js
const Seneca=require('seneca-await');
const seneca=Seneca();
seneca.client({port:10,host:"localhost",pin:{role:'test'}}) //pin可以不要,就是个精确匹配
const response= seneca.act({
role:"test",
cmd:"sayhello",
name:"lin"
}); //寻找为服务,并传一些json数据,判断是哪一个
response.then(function(a){ //返回的数据
console.log(a)
})