Skip to content

Modern solution for communications between microservices, for NodeJS

Notifications You must be signed in to change notification settings

spyzhov/babex-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

Babex is a modern solution for communications between microservices.

Versions

Version 1

Input message:

{
  "data": Any,
  "chain": [Path],
  "config": Any
}

Where Path like:

{
  "exchange": String,
  "key": String,
  "isMultiple": Bool,
  "successful": Bool
}

Example

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
}

Other languages

About

Modern solution for communications between microservices, for NodeJS

Resources

Stars

Watchers

Forks

Packages

No packages published