Skip to content

nodecloud/loadbalance-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

loadbalance-client

Usage

import LoadBalanceClient from 'loadbalance-client';
import Consul from 'consul';

const SERVICE_NAME = 'a-service';

const consul = new Consul(/* ignore */);
const lbClient = new LoadBalanceClient(SERVICE_NAME, consul);

export function getResource(id) {
    return lbClient.get({
        url: `/${SERVICE_NAME}/v1/resources/:id`,
        params: {id: id},
        headers: {
            'Content-Type': 'application/json'
        }
    });
}

API

new LoadBalanceClient(serviceName, consul, options)

serviceName

The service name.

consul

The consul client instance. you can see node-consul for detail.

options

  • strategy: Default is random. Others are 'round_robin_engine', 'priority_engine'.
  • request: You can see request for detail.
  • Other options you can see node-consul for detail.

lbClient.get(options)

lbClient.post(options)

lbClient.delete(options)

lbClient.put(options)

lbClient.send(options)

If you use send function, you must specific the options.method param. You can see request for detail. This options have a higher priority than global options.

lbClient.onPreSend(callback: request)

lbClient.onPostSend(callback: response)

Event

support events:

  • refreshing-services

lbClient.on(eventName, callback);

lbClient.off(eventName, callback);

About

An http client by request with loadbalance.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •