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'
}
});
}The service name.
The consul client instance. you can see node-consul for detail.
- 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.
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.
support events:
- refreshing-services
lbClient.on(eventName, callback);
lbClient.off(eventName, callback);