Messaging communicator for NodeJs microservice
npm install sauromjs
API
Import package
const Saurom = ;
Request
Creating a request object
const request = instanceId: 'id1' // Default: auto generate an uniq id. Each nodejs instance must have an uniq instance id, mqUrl: 'amqp://localhost' // Default 'amqp://localhost' timeout: 2000 // Default 5000. Request timeout ;
Connect to message queue
request ;
Call a repository's service
request;
Example
const request = ; request ;
Service
Creating a service object
const service = repository: 'MathRepository' // required instanceId: 'id2' // default: auto generate an uniq id mqUrl: 'amqp://localhost' // default 'amqp://localhost'. Queue url, using amqplib package to connect message queue. Please see http://www.squaremobius.net/amqp.node/channel_api.html#connect for detail ;
Connect to message queue
service ;
Define service
service;
Example
const service = repository: 'MathRepository' // required ; service; service;
Example
See more example at: https://github.com/nhuanhoangduc/sauromjs/tree/master/test
1. Request.js - Make request to UserRepository microservice
// --- Step 1: Import sauromjs packageconst Saurom = ; // --- Step 2: Create a Request objectconst Request = ; // --- Step 3: connect to message queueRequest ;
2. MathRepository.js - Receive request message and send response message
// --- Step 1: Import sauromjs packageconst Saurom = ; // --- Step 2: Create a Service objectconst Service = repository: 'MathRepository' // required; // --- Step 3: Define services for repository MathRepository // Service 'sqrt' of repository MathRepositoryService; // Service 'pow' of repository MathRepositoryService; // --- Step 4: connect to message queueService ;