An HTTP client with load balancing, supporting various strategies to interact with services registered in Eureka.
To install this package, you can use npm:
npm install balanced-http-client
Usage
To use this package, import the EndpointCaller, InstanceManager, and LoadBalancer classes and configure the Eureka client.
Requirements
This package depends on axios to perform HTTP requests.
Usage
To use this package, you need to instantiate the EndpointCaller class with your Eureka client. The class will automatically create instances of InstanceManager and LoadBalancer.
const { EndpointCaller } = require('balanced-http-client');
const eurekaClient = require('./eurekaClient'); // Make sure your Eureka client is properly configured
// Instantiate the EndpointCaller with the Eureka client
const endpointCaller = new EndpointCaller(eurekaClient);
// Call an endpoint with a load balancing strategy
const response = await endpointCaller.get('MY-NODE-APP', 'some/endpoint', 'roundRobin');
console.log(response);
Load Balancing Strategies
The client supports the following load balancing strategies:
Round Robin: Selects instances cyclically.
Least Connections: Selects the instance with the least active connections.
Random: Selects a random instance.
Contributing
Contributions are welcome. If you would like to improve the package, please open an issue or submit a pull request.