Install via npm+git: npm install hexa1/eureka-client-js --save
.
import EurekaClient from 'eureka-client-js';
const myClient = new EurekaClient({
// ... options, see below
});
myClient.register();
The following options are available:
Option | Type | Description | Required | Default value |
---|---|---|---|---|
eurekaHost |
string | host:port of your Eureka registry | yes | |
instance |
object | see Instance Options below | yes | |
registerRetryInterval |
number | how long to wait after a failed registration before attempting again, in seconds | no | 5 |
retryRegisterAfter |
number | how many failed heartbeat attempts can occur before attempting to re-register | no | 3 |
heartbeatInterval |
number | how often to send a heartbeat, in seconds | no | 5 |
registryInterval |
number | how often to fetch the registry, in seconds | no | 15 |
logLevel |
string | see winston logging levels | no | info |
The instance
object should conform to the Eureka XSD spec: https://github.com/Netflix/eureka/wiki/Eureka-REST-operations.
The only difference is that you should pass instanceId
inside the instance
object. This value isn't passed to Eureka during registration but it is used for crafting the URLs when making requests to Eureka.
The following methods are available after instantiating a new EurekaClient object:
register()
: registers with the eureka registry. will continue to try to re-register if registration failsstopRegisterRetry()
: if registration fails it will automatically retry itself according to theregisterRetryInterval
option. Use this if you want to stop that retry loop.deregister()
: deregisters with the eureka registryfetchRegistry()
: gets the latest list of instances from the eureka registry, stores in internal cachestartRegistryFetcher()
- runsfetchRegistry()
at the interval specified in optionsstopRegistryFetcher()
- stops fetching the registrygetInstanceByAppId(appId)
- gets the first available instance of an app on the registrysendHeartbeat()
- sends a heartbeat for this servicestartHeartbeats()
- runssendHeartbeat()
at the interval specified in optionsstopHeartbeats()
- stops sending heartbeatsmiddleware()
- see Middleware
This is an express-compatible middleware that provides endpoints used by the Eureka server for determining the health of the service.
The following endpoints are provided:
/info
/health
/metrics
/env
const app = express();
const myClient = new EurekaClient({
// ...options
});
app.use(myClient.middleware());
npm run test
npm run coverage
to get code coverage stats
Please lint all code before committing: npm run lint
.
The package needs to be built and the built files committed: npm run build
.
- Allow passing a custom
winston
logging transport, e.g. for remote logging