moshi-moshi
v1.0.6
Published
amqp wrapper for Req/Rep pattern
Downloads
7
Readme
README desu
THIS IS A EXPERIMENTAL PACKAGE
Each created queue has one response queue, which receive messages from the sender, while asker wait for response on response queue, it's like LeanKit-Labs/wascally but using postwait/node-amqp as backend and made by a totally amateur programmer :bowtie:
And yes, it's a unexpected behaviour of an message queue service, unless we are talking about RPC. But who cares?
Proposal
var phone = require('moshi-moshi');
// receiver
phone('exchange', /*...amqp connection info*/)
.then(function(connection) {
connection
.withQueue('the-queue', ['notice' /* routing keys */], /* queue options */) // return event emitter, is that wrong? Yes. Maybe a Stream could be cooler.
.on('message', function(message) {
message.reply('SENPAI NOTICED ME'); // auto acknowledge of `message`
})
.on('yaddayaddayadda', function(yaddayaddayadda) {
yaddayaddayadda.yaddayaddayadda();
});
})
.catch(function(error) {
console.error("HOLY C##P");
});
// sender
phone('exchange', /*...amqp connection info*/)
.then(function(connection) {
connection
.askFor('notice')
.timeout(1000) // timeout from bluebird
.then(function(reply) {
console.log(reply.body);
})
.catch(function(error) {
console.error("uh-oh");
});
})
.catch(function(error) {
console.error("HOLY C##P");
});
TODO
- CANCELLABLE EVERYTHING
- code style
- find a good naming convention