- Open source framework for building event-driven microservices.
- Scalability the code is automatically scalable with no change in the code.
- Availability as long as the cluster is running and there are instances everything is fine!
- Durability events can't be lost even after a cluster reboot. (TODO:Migration to NATS Jetstream)
- Easy deploy your application without modifying the code.
1. Run the nats-server Docker image.
> docker run -p 4222:4222 -p 8222:8222 -p 6222:6222 --name nats-server -ti nats:latest
2. Install the package inside your project
> npm i @diffty/bullma
// or
> yarn add @diffty/bullma
And.. Finish!!
require("@diffty/bullma")(
"namespace1",
/* optional */ {
transport: {
// nats config
servers: ["127.0.0.1:4222"],
},
config: {
// global config
whoami: "I'm bullma",
},
}
)
.then((Service) => {
Service(
"myservice1",
async (config, exports, emit) => {
console.log("init", "myservice1");
exports("gettime", () => Date.now());
exports.myservice2.on("testevent", (...msg) => {
console.log("myservice1", "testevent", ...msg);
});
},
/* optional */ {
mylocalvar1: "test1",
}
);
Service(
"myservice2",
async (config, exports, emit) => {
console.log("init", "myservice2");
console.log("myservice2", await exports.myservice1.gettime());
emit("testevent", "hello world", "mdr", 12);
},
/* optional */ {
mylocalvar1: "test2",
}
);
})
.catch(console.log);