0.2.23 • Published 4 years ago

rams-call v0.2.23

Weekly downloads
18
License
MIT
Repository
-
Last release
4 years ago

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.

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

MIT

Copyright (c) 2019, Owen Luke

0.2.23

4 years ago

0.2.22

4 years ago

0.2.21

4 years ago

0.2.20

4 years ago

0.2.19

4 years ago

0.2.18

4 years ago

0.2.15

4 years ago

0.2.17

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.11

4 years ago

0.2.9

4 years ago

0.2.8

4 years ago

0.2.10

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago