Dooms
A RPC microservices framework for Node.js, loads a directory as a microservice, calls remote functions in it like s1.say.hi() or call('s1:/say/hi'). Dooms is based on gRPC-node, but no proto files needed, more easy to use.
Server Environment
1. Install Docker (Docker CE recommended)
2. Install Redis in Docker
1) Install: docker pull redis
2) Start: docker run --restart=always --name redis -d -p 6379:6379 -it redis redis-server
Install
npm install dooms --save
Test
Download this repo
git clone https://github.com/hiowenluke/dooms.gitcd doomsnpm install
Test
npm test
TRY IT!
To run this demo, download this repo first if not yet (see above).
1. Run microservices
1) Open a new tab in terminal, then:
node ./examples/service1# Service s1 is running...
2) Open a new tab in terminal, then:
node ./examples/service2# Service s2 is running...
2. Run client
1) Open a new tab in terminal, then:
node ./examples/client-with-object-style # Microservices #1 # Microservices #2 # { msg: 'Hi, I\'m owen, 100 years old.' }
2) Open a new tab in terminal, then:
node ./examples/client-with-message-style # Microservices #1 # Microservices #2 # { msg: 'Hi, I\'m owen, 100 years old.' }
Usage
1. Create function files in directory "./src" in server project, such as below:
moduleexports = async { return msg: `Hi, I'm , years old.`;};
2. Load the directory "./src" as a microservice named "s1" in index.js.
// "s1"// The name of this microservice.// It can be omitted if you have only one microservice. // "./src"// The root folder name of business files such as "src/say/hi.js".// It can be omitted or replaced with other names such as "./biz", "./src", etc.// It should be started with ".". ;
3. Call like s1.say.hi()
const services = ; const main = async { const s1 = await ; const result = await s1say; console; // {msg: 'Hi, I\'m owen, 100 years old.'}}; ;
4. Call like call('s1:/say/hi')
const call = ; const main = async { const result = await ; console; // {msg: 'Hi, I\'m owen, 100 years old.'}}; ;
Options
1. For server
const options = // Specify the gRPC options. // It can be omitted if the host is "localhost". gRPC: host: 'localhost' // gRPC host // Specify the Redis options. // It can be omitted if it is the default options (like below) of Redis. redis: host: 'localhost' // Redis host // port: '6379', // Redis port // db: 0, // Redis database number // family: 4, // 4 (IPv4) or 6 (IPv6) ;
Use it
;
2. For client
Only redis options required.
const options = // Specify the Redis options. // It can be omitted if it is the default options (like below) of Redis. redis: host: 'localhost' // Redis host // port: '6379', // Redis port // db: 0, // Redis database number // family: 4, // 4 (IPv4) or 6 (IPv6) ;
Use it
;
Or
;
Example
See files in directory examples to learn more.
Performance
Dooms is extended from gRPC-node. It is as fast as gRPC-node, much faster than socket.io-based RPC. (See Benchmark)
Why
- Why Enterprises Are Embracing Microservices and Node.js
- Microservices With Node.js: Scalable, Superior, and Secure Apps
License
Copyright (c) 2019, Owen Luke