Babex
is a modern solution for communications between microservices.
Input message:
{
"data": Any,
"chain": [Path],
"config": Any
}
Where Path
like:
{
"exchange": String,
"key": String,
"isMultiple": Bool,
"successful": Bool
}
Service example Sum(a, b)
:
Request:
{
"data": {
"a": 2,
"b": 3
},
"chain": [
{
"exchange": "math",
"key": "math.sum",
"isMultiple": false
},
{
"exchange": "math",
"key": "sum.next",
"isMultiple": false
}
],
"config": null
}
const babex = require('babex-node');
const exchange = 'math';
const routingKey = 'math.sum';
const config = babex.config;
config.name = 'math.sum';
config.address = process.env.RMQ_ADDRESS;
babex
.newService(config)
.then((service) => service
.bindToExchange(exchange, routingKey)
.then((service) => service
.listen((message) => {
let payload = {
c: message.data.a + message.data.b
};
service.next(message, payload);
})
)
)
.catch(console.warn);
Result:
{
"data": {
"c": 5
},
"chain": [
{
"exchange": "math",
"key": "sum",
"isMultiple": false,
"successful": true
},
{
"exchange": "math",
"key": "sum.next",
"isMultiple": false,
"successful": false
}
],
"config": null
}
- Golang - https://github.com/matroskin13/babex
- Python - https://github.com/spyzhov/babex-py