process.on('kill', () => {})
, but i want to capture it on the seneca level - something like seneca.on('disconnect', () => {})
kinda thing.
Hey everyone!
I am a new Seneca user trying to use Seneca as part of my fairly simple Express/MongoDB setup. More specifically, I am trying to make my models use seneca-entity backed by seneca-mongo-store. This works great, but I cannot find a good way to implement some kind of schema validation.
In a previous project, I used Mongoose to create schemas which would automatically validate the data upon creation/update. I would like a similar thing here but I could not find good documentation about mongoose/seneca integration online and it feels like Mongoose would be fairly redundant here, or at least a bit clunky to integrate. I feel like there's got to be a better way.
Am I doing this wrong? How are you guys validating your mongodb data with seneca entities?
Thank you all in the community for building this project!
hi , i am just try to custom my logger and check this tutorials/logging-with-seneca
http://senecajs.org/docs/tutorials/logging-with-seneca.html
D:\code\seneca-log-test\sales-tax-log-handler.js:8
{level: 'all', handler: seneca.loghandler.file('shop.log')}
^
TypeError: Cannot read property 'file' of undefined
at Object.<anonymous> (D:\code\seneca-log-test\sales-tax-log-handler.js:8:49)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
================================
any sugguestion?
https://github.com/spsingh559/microserviceTemplate
This is reference implementation of Seneca microservices along with API hosted on node js server. It may help to see the entire Seneca flow.
Seneca Microservices discover each other using mesh network, once you publish a message, mesh find out the best matching pattern and deliver the message to the corresponding microservice.
So you are right, anyone will respond out of two if defined by the same pattern.
But if your use case is to send the same message to two microservices, as I said " use two different patterns" something like this "type:client, cmd:message" and "type:client, cmd:duplicateMessage".
And conceptually one microservice should do one dedicated task, assigning two MS to process similar tasks is not desirable.
prior
method must be called inside an action function. Arguments were: [Arguments]module.exports = function(options) {
this.add({role: 'math', cmd: 'sum'}, (msg, done) => {
done(null, {answer: msg.left + msg.right});
});
this.add({role: 'math', cmd: 'product'}, (msg, done) => {
done(null, {answer: msg.left * msg.right});
});
this.add({role: 'math', cmd: 'sum', integer: true}, (msg, done) => {
done(null, {answer: Math.floor(msg.left) + Math.floor(msg.right)});
});
this.add({role: 'math', cmd: 'sum'}, (msg, done) => {
if (isFinite(msg.left) && isFinite(msg.right)) {
this.prior({role: 'math', cmd: 'sum', left: msg.left, right: msg.right}, (err, result) => {
if( err ) return done( err );
result.info = msg.left + ' + ' + msg.right;
done(null, result);
});
}
else {
done(new Error('Expected left and right to be numbers.'), null);
}
});
return 'operations';
}
@ks32849 I don't know why are you defining role:'math',cmd:'sum' twice, its already been declared on top.
And since you are not over riding any function, prior has no use here and unless and until you want one function to handle multiple use case. Check the proper uses of prior function along with right syntax here
https://senecajs.org/docs/tutorials/understanding-prior-actions.html
const seneca=require('seneca')();
seneca
.add({role: 'math', cmd: 'sum'}, function(msg, done){ //declaring without arrow function
done(null, {answer: msg.left + msg.right});
})
.add({role: 'math', cmd: 'product'}, function(msg, done) { //declaring without arrow function
done(null, {answer: msg.left * msg.right});
})
.add({role: 'math', cmd: 'sum', integer: true}, function(msg, done) { //declaring without arrow function
done(null, {answer: Math.floor(msg.left) + Math.floor(msg.right)});
})
.add({role: 'math', cmd: 'sum'}, function(msg, done) { //declaring without arrow function
if (isFinite(msg.left) && isFinite(msg.right)) {
this.prior(msg, (err, result) => { //pass the message object only, no need to pass pattern
if( err ) return done( err );
result.info = msg.left + ' + ' + msg.right;
done(null, result);
});
}
else {
done(new Error('Expected left and right to be numbers.'), null);
}
})
//testing the role math, cmd: sum service
.act({role: 'math', cmd: 'sum',left: 10, right: 5},function (err,output){
console.log(err,output); //null { answer: 15, info: '10 + 5' }
})
@ks32849 your updated code, i hope this works for you.
module.exports = function(options) {
this.add({role: 'math', cmd: 'sum'}, function(msg, done) {
done(null, {answer: msg.left + msg.right});
});
this.add({role: 'math', cmd: 'product'}, function(msg, done) {
done(null, {answer: msg.left * msg.right});
});
this.add({role: 'math', cmd: 'sum', integer: true}, function(msg, done) {
done(null, {answer: Math.floor(msg.left) + Math.floor(msg.right)});
});
this.add({role: 'math', cmd: 'sum'}, function(msg, done) {
if (isFinite(msg.left) && isFinite(msg.right)) {
this.prior(msg, (err, result) => {
if( err ) return done( err );
result.info = msg.left + ' + ' + msg.right;
done(null, result);
});
}
else {
done(new Error('Expected left and right to be numbers.'), null);
}
});
return 'operations';
}
@rajatprogrammer could you please elaborate more on the issue.
I have tried replicating the problem as far as i understand
created a docker rabbitmq docker image from here https://www.rabbitmq.com/download.html
now created a Seneca listener and seneca client as mentioned here https://github.com/senecajs/seneca-amqp-transport
Note : My URL is : amqp://guest:guest@127.0.0.1:5672/
which means for my user name and password is guest:guest and connected local instance of Rabbit MQ 127.0.0.1 ( you can replace with cloud IP) with 5672 port and vhost is "/" . Make sure 5672 port is open in cloud service
and here are the results :