https://github.com/udamir/node-ipc-rpc
IPC and RPC service for nodes in scalable application
https://github.com/udamir/node-ipc-rpc
ipc redis rpc
Last synced: about 1 year ago
JSON representation
IPC and RPC service for nodes in scalable application
- Host: GitHub
- URL: https://github.com/udamir/node-ipc-rpc
- Owner: udamir
- License: mit
- Created: 2021-08-23T22:20:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-23T22:23:56.000Z (over 4 years ago)
- Last Synced: 2025-01-14T06:47:48.357Z (about 1 year ago)
- Topics: ipc, redis, rpc
- Language: TypeScript
- Homepage:
- Size: 54.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# node-ipc-rpc
Internal process communication (IPC) and Remote procedure calls (RPC) service for nodes of scalable application.
Nodes discovery and communication can be handled by Redis.
# When it required?
When scaled nodes need
1. discover other instances
2. send messages to instance or all instances (broadcast)
3. call remote function on instance and get result
# Quick start
## Installation
```
npm install --save node-ipc-rpc ioredis
```
## Create IPC via Redis
```ts
import Redis from "ioredis"
import { RedisIpc } from "node-ipc-rpc"
const redis = new Redis("redis://127.0.0.1:6379")
const pid = Date.now().toString(24)
// declare methods for all node instances
interface Methods {
sum: (a: number, b: number) => Promise
}
const ipc = new RedisIpc(redis, pid)
ipc.declare("sum", (a: number, b: number) => a + b)
// handle instance connection
ipc.on("connect", async (node) => {
const result = await node.sum(1, 2)
console.log(result) // 3
})
// handle incoming messages
ipc.on("test", (node, data) => {
console.log(data) // "message" on other instances
})
// send message to all instances (self exclusive)
ipc.sendAll("test", "message")
// gracefull shutdown
ipc.close()
```
# License
MIT