mateodelnorte / servicebus

Simple service bus for sending events between processes using amqp.
MIT License
420 stars 66 forks source link

Being Able to send back data in response. #87

Closed ppinel closed 7 years ago

ppinel commented 7 years ago

Hello,

Thank you for your hardwork and happy new year.

I read this issue https://github.com/mateodelnorte/servicebus/issues/48. I wanted to know if a feature that allow the Process that receive the message to send back a response could match the vision of this project.

It's not only to know if sending the message is a success or a failure but also receiving data in return.

mateodelnorte commented 7 years ago

The callback to send and publish denote that the broker has received a message fully, not the recipient application(s).

servicebus exists to provide asynchronous communication. If you want a request response pattern, you can implement it yourself pretty simply.

application 1:

const bus = require('servicebus').bus();

bus.listen('response', (msg) => { console.log(msg); });

setInterval(function () { bus.send('request', { value: Math.random() } }, 5000);

app 2:

const bus = require('servicebus').bus();

bus.listen('request', (msg) => { 
  bus.send('response', { value: `thanks for sending me a random ${msg.value}` });
});

The same can be done with any combination send/listen + publish/subscribe.