senecajs / seneca-mesh

Mesh your Seneca.js microservices together - no more service discovery!
MIT License
142 stars 47 forks source link

seneca-mesh fires a warning message 'unknown_message_id' when 'model:observe' is used #69

Open jack-y opened 7 years ago

jack-y commented 7 years ago

This kind of warning message is fired:

2016-11-25T07:11:43.945Z cxr3pi64dn03/1480057900449/9508/- WARN -   -   ACT 05dvr66o6n8p/jmm290cgl1mb   name:transport,plugin:define,role:seneca,seq:3,tag:undefined    plugin  transport   ACT g3o0affyihgf/l7h781gglewa   hook:client,role:transport,type:web client  unknown_message_id  {type:web,port:58218,host:localhost,path:/act,protocol:http,timeout:5555,max_listen_attempts:11,attempt_delay:2 {kind:res,res:{success:true},error:null,sync:true,id:5g2cjv86apgw/ki74z33vk0w5,origin:cxr3pi64dn03/148005790044

package.json

The dependencies used are:

"seneca": "~2.1.0",
"seneca-balance-client": "^0.6.0",
"seneca-mesh": "^0.9.0"

The mesh-base script

First, this basic mesh-base script is started in a terminal:

var seneca = require('seneca')();
seneca.ready(function(err) {
    seneca.use('mesh', {
        isbase: true,
        host: 'localhost'
    });
});

The microservice

The simple test plugin.js is:

module.exports = function plugin(options) {
    var seneca = this;
    seneca.add({role: 'test', cmd: 'test'}, test);
    function test(args, done) {
        console.log('test: ' + JSON.stringify(args));
        done(null, {success: 'true'});
    }
};

And the test microservice is started with this simple script:

const seneca = require('seneca')();
seneca.ready(function(err) {
    seneca
    .use('plugin')
    .use('mesh', {
        host: 'localhost',
        listen: [
            {pin: 'role:test,cmd:test', model: 'observe'}
        ]
    });
});

Tests

The test.js script is:

var seneca = require('seneca')();
seneca.ready(function(err) {
    seneca.use('mesh', {
        host: 'localhost'
    });
    seneca.act({role: 'test', cmd: 'test', msg: 'Hello World!'}, (err, done) => {
        if (err) { throw err; }
        console.log('test-mesh done.');
    });
    seneca.close((err) => {
        if (err) { console.log(err); }
        else { console.log('seneca closed.'); }
    });
});

When only one instance of the microservice is running in a terminal, all is fine. When a second instance of the microservice is running in another terminal, the test script fires one warning message. And when a third instance is running in another terminal, the test script fires two warning messages.

What can be wrong?

W1U02 commented 7 years ago

This is because when you call done, it will fire an action to send the result to the caller. But after the caller recieved the first response, the listener will be closed.

jack-y commented 7 years ago

@W1U02: Great answer! So should I let the listener always open? (And how to do it?)

W1U02 commented 7 years ago

@jack-y the listener is created in mesh and I have no idea about how to keep it open. May be we can check with @rjrodger if this is by design.