New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

request-balancer

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-balancer

Provide local load balancer on top of request promise, usefull for microservice call

latest
Source
npmnpm
Version
0.0.1
Version published
Weekly downloads
3
-50%
Maintainers
1
Weekly downloads
 
Created
Source

request-balancer

HTTP(s) Local load balancer client based on request-promise : https://www.npmjs.com/package/request-promise

installation

npm install request-balancer

Description

The main porpose of this library is to provide a basic HTTP(s) load balancer client to send http request to a microservice composed of several nodes, as netflix OSS java 'Ribbon' library does.

Now imagine you have deploy three instance of your microservice with the following host and port:

nodehostport
#1node1.test.domain.org3010
#2node2.test.domain.org3020
#3node3.test.domain.org3070

Each instance expose a service to get the weather using the following request : GET http://{host:port}/weather?town=paris

To load balance over this three instances you must use request-balancer as follow:


let Rpb = require('../request-balancer');

let rpb = new Rpb(['http://node1.test.domain.org:3010', 'http://node2.test.domain.org:3020', 'http://node3.test.domain.org:3070'], {
            timeout: 2000,
            maxError: 1
        });

rpb.send({
	path:'/weather?town=paris',
	method:'GET'
}).then(function(response){
	console.log(response);
});

Request balancer come as class you must instanciate to keep the context of round robin balancing

new Rpb(endpoints,options)

  • endpoints : is an array of uri of all the endpoints to load balance on
  • options
    • timeout : in order to 'fail fast', it is possible to set the timeout on a request send to endpoints. If it timeout, load balancer send the request to the next endpoint.
    • maxError : maximum number of consecutive error after the library consider the endpoint as dead, error counter are reset every healthCheckPeriod
    • healthCheckPeriod : period after the library perform a health check on each endpoint

rpb.send(options)

  • options same as original request library except:
    • path replace the uri field of request, instead of providing the full uri only the uri path is provided

Keywords

microservice

FAQs

Package last updated on 09 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts