mxriverlynn / rabbus

A micro-service bus with built-in messaging patterns, for NodeJS and RabbitMQ
116 stars 26 forks source link

Only one callback can be registered per requester #15

Closed shurik239 closed 8 years ago

shurik239 commented 8 years ago

The following code:

requester.request(msg1, function(response){
    console.log("first callback");
});

requester.request(msg2, function(response){
    console.log("second callback");
});

will result:

first callback
first callback

plus error in docs:

requester.request(msg, function(response, done){
  console.log("Hello", response.place);
  done();
});

done is undefined

mxriverlynn commented 8 years ago

d'oh! that done call shouldn't be there. replies have an automatic ack() called on them...

of course, now that is say that i think this should not be the case. there should be a fn(message, actions) signature on the callback so you can decide what to do with the reply.

for the duplicate first callback problem, i'm looking into it now. will let you know what i find.

mxriverlynn commented 8 years ago

i duplicated the issue with a new test, sending two requests through the same object instance. as you show in your example, the first callback for the response handler is the only one being used. i'll have to dig into this further to figure out what the issue is and see what i can do to fix it

mxriverlynn commented 8 years ago

I think I found the problem in the way I'm using middleware. still investigating, and will hopefully have a fix in a day or two, depending on when i can get back to this.

mxriverlynn commented 8 years ago

i opened a ticket with the middleware project to see if they can add a feature to help me solve this problem: https://github.com/alessioalex/generic-middleware/issues/14

shurik239 commented 8 years ago

Thank you very much, Derick, for rapid response/investigation on this issue.

If we are speeking about reply/callback approach, i would suggest a feature request: If I understand it right, you send-receive pattern from Rabbus implements Command Messaging pattern from your book "RabbitMQ: Patterns for Application" (BTW, excelent work, thank you). It would be nice, if command consumer (receiver in Rabbus) could alsosay to producer, that the work is done.

mxriverlynn commented 8 years ago

@shurik239 can you open the feature request as a new issue? I don't want to get the issue in this one confused with that conversation

mxriverlynn commented 8 years ago

FWIW, I have a working solution in the "middlewareBuilder" branch. it's not really the best way to do things, yet, so i'm not quite ready for a release. I need to try one more idea based on discussion with @alessioalex in the linked ticket from his generic-middleware project. hopefully i'll get this fixed and done tonight. there's one other change I want to make before another release, as well. should be done and released on Wednesday, sometime (Feb 3rd).

shurik239 commented 8 years ago

Great! Thank you!

mxriverlynn commented 8 years ago

fixed in v0.7.1