README
yello
Communication primitives for microservices on top of AMQP.
This module handles the main communication challenges our apps face in our microservice architecture. Both request/response type and publish/subscribe. It handles topic based subscription as well.
API
Create a new client.
var yello = require('yello');
var client = yello('amqp://user:password@amqphost');
request/response
Just keep in mind, by default these handlers will only handle 1 request concurrently.
Use maxConcurrency
option to increase that limit.
API providers can set up endpoints:
client.respond('sayHello', request => {
// response can either be a value or a promise
return Promise.resolve({
message: `Hello ${request.name}!`
});
});
To which clients can request:
client.request('sayHello', { name: 'Yello' })
.then(response => {
console.log(response.message);
// "Hello Yello!"
})
publish/subscribe
Just keep in mind, by default these handlers will only handle 1 request concurrently.
Use maxConcurrency
option to increase that limit.
Distributed worker
Multiple registrations under the same worker Id. Only one will receive the event. Useful for distributed workers.
// instance 1
client.subscribe('emailSvc', 'emails.pwRecovery', job => {
return sendEmail(job.email);
});
// instance 2
client.subscribe('emailSvc', 'emails.pwRecovery', job => {
return sendEmail(job.email);
});
Only one of these will receive the event when we publish
it:
client.publish('emails.pwRecovery', { email: 'yello@example.com' });
Catch all events
Multiple registrations, Each one will receive the event.
// instance 1
client.subscribe(null, 'config.refresh', () => {
return config.refresh();
});
// instance 2
client.subscribe(null, 'config.refresh', () => {
return config.refresh();
});
Both will receive the event when we publish
it:
client.publish('config.refresh');
Topic based subscription
client.subscribe('emailLogger', 'emails.*', job => {
return console.log(`Received email job for ${job.email}`);
});