senecajs / seneca-transport

Seneca micro-services message transport over TCP and HTTP.
MIT License
63 stars 45 forks source link

Pins not working? #97

Closed mcdonnelldean closed 5 years ago

mcdonnelldean commented 8 years ago

Via,

https://github.com/senecajs/seneca/issues/173

I'm not sure if I'm understanding the point in listening with a pin pattern.

The documentation makes it sound like when you use pin in listen, it only allows for those matched actions to be executed: "A pin is a pattern that matches other patterns (it “pins” them). The pin role:math will match the patterns role:math,cmd:sum and role:math,cmd:product that are registered with Seneca"

So with the following code:

require('seneca')()
    .add('role:shop,cmd:purchase', function (msg, respond) {
        var purchase = {
            name: msg.name
        };

        this.act('role:shop,info:purchase', { purchase: purchase });

        respond(null, purchase);
    })
    .add('role:yolo,cmd:hard', function (msg, respond) {
        respond(null, { yolo: 'hard' });
    })
    .listen({ port: 9002, pin: 'role:shop' })
    .client({ port: 9003, pin: 'role:shop,info:purchase' });

I would expect that hitting http://localhost:9002/act?role=yolo&cmd=hard should return a 404/error.

What does work is that setting the pin in the client maps all actions to the correct seneca service and errors when a match isn't made or the service doesn't exist, which seems correct.

Am I looking at this wrong or is this a bug?