rams-call v0.2.23
Rams Call
A lite version of the Node.js microservices framework Rams. Rams Call loads a directory as a microservice, so that the client can calls remote functions with Message Style like call('service1:/do/say/hi', 'Hello world!') and gets the results immediately.
Rams Call is based on RabbitMQ. If you wanna to call remote functions with Object Style like service1.do.say.hi('Hello world!'), try Rams.
- Why Enterprises Are Embracing Microservices and Node.js
- Microservices With Node.js: Scalable, Superior, and Secure Apps
Server Environment
1. Install Docker (Docker CE recommended)
2. Install RabbitMQ in Docker
1) Install: docker pull rabbitmq:management
2) Start: docker run --restart=always --name rabbitmq -d -p 5672:5672 -p 15672:15672 rabbitmq:management
3) Login to RabbitMQ management web page: http://localhost:15672/
(guest/guest)
Install
npm install rams-call --save
Test
Download this repo
git clone https://github.com/hiowenluke/rams-call.git
cd rams-call
npm 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 ./example/service1
# Service s1 is running...
2) Open a new tab in terminal, then:
node ./example/service2
# Service s2 is running...
2. Run client
Open a new tab in terminal, then:
node ./example/client
# Microservices #1
# Microservices #2
# { msg: 'Hi, I\'m owen, 100 years old.' }
Usage
1. Create functions in directory "./src" in server project, such as below:
module.exports = async (name, age) => {
return {msg: `Hi, I'm ${name}, ${age} years old.`};
};
module.exports = async () => {
return `Microservices #1`;
};
2. Load the directory "./src" as a microservice named "s1" in index.js.
require('rams-call').initServer('s1');
You can specify another directory such as "./biz" instead of "./src", like below:
require('rams-call').initServer('s1', './biz');
3. Client: call the remote functions with Message Style.
const call = require('rams-call').initClient();
const main = async () => {
let result;
result = await call('s1:/about');
console.log(result); // "Microservices #1"
result = await call('s1:/say/hi', 'owen', 100);
console.log(result); // {msg: 'Hi, I\'m owen, 100 years old.'}
};
main();
Options
// Specify the rabbitMQ host via options.rabbitMQ.host.
// The options can be omitted if it is "localhost".
const options = {
rabbitMQ: {
host: 'localhost',
},
};
For initializing server:
require('rams-call').initServer('s1', options);
For initializing client:
require('rams-call').initClient(options);
Example
See files in directory example to learn more.
License
Copyright (c) 2019, Owen Luke
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago