1.0.3 • Published 6 years ago
proton-cluster v1.0.3
A clustered starter for Node.js applications
Starting workers by CPUs
ProtonCluster.startByCPUS(() => {
console.log("Process");
});
Starting workers by specified number
ProtonCluster.start(8, () => {
console.log("Process");
});
Starting Protontype application
ProtonCluster.startByCPUS(() => {
new ProtonApplication()
.addRouter(new TasksRouter())
.start();
});
Setup events behaviors
Events behaviors should be configured before start clusters.
ProtonCluster.onOnline(worker => {
console.log(`I am Online Event`);
});
ProtonCluster.onExit(worker => {
console.log(`I am Exit Event`);
});
ProtonCluster.onDisconnect(worker => {
console.log(`I am Disconnect Event`);
});
ProtonCluster.onMessage(worker => {
console.log(`I am Message Event`);
});
ProtonCluster.startByCPUS(() => {
console.log("Test");
});
Cluster instance
You can access native Node.js cluster instance
let cluster = ProtonCluster.cluster;
cluster.on("online", worker => {
console.log(`Cluster ${worker.process.pid} online`);
});