0.2.2 • Published 5 years ago

loadbalance-client v0.2.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

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);

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago