Skip to content

Commit

Permalink
Merge pull request #31 from jquatier/disable-registry-polling
Browse files Browse the repository at this point in the history
Allowing optional disabling of registry polling.
  • Loading branch information
jquatier committed Jan 6, 2016
2 parents 8ea4fa6 + e3654cd commit c99857c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default {
eureka: {
heartbeatInterval: 30000,
registryFetchInterval: 30000,
fetchRegistry: true,
servicePath: '/eureka/v2/apps/'
},
instance: {}
Expand Down
19 changes: 12 additions & 7 deletions src/eureka-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const noop = () => {};

/*
Eureka JS client
This module handles registration with a Eureka server, as well as heartbeats
This module handles registration with a Eureka server, as well as heartbeats
for reporting instance health.
*/

Expand Down Expand Up @@ -60,7 +60,7 @@ export class Eureka {
}

/*
Helper method to get the instance ID. If the datacenter is AWS, this will be the
Helper method to get the instance ID. If the datacenter is AWS, this will be the
instance-id in the metadata. Else, it's the hostName.
*/
get instanceId() {
Expand All @@ -79,7 +79,10 @@ export class Eureka {
this.register(done);
},
done => {
this.fetchRegistry(done);
if (this.config.eureka.fetchRegistry) {
return this.fetchRegistry(done);
}
done();
}
], callback);
}
Expand Down Expand Up @@ -117,14 +120,16 @@ export class Eureka {
register(callback = noop) {
this.config.instance.status = 'UP';
request.post({
url: this.eurekaUrl + this.config.instance.app,
url: this.eurekaUrl + this.config.instance.app,
json: true,
body: {instance: this.config.instance}
}, (error, response, body) => {
if (!error && response.statusCode === 204) {
this.logger.info('registered with eureka: ', `${this.config.instance.app}/${this.instanceId}`);
this.startHeartbeats();
this.startRegistryFetches();
if (this.config.eureka.fetchRegistry) {
this.startRegistryFetches();
}
return callback(null);
} else if (error) {
return callback(error);
Expand All @@ -138,7 +143,7 @@ export class Eureka {
*/
deregister(callback = noop) {
request.del({
url: `${this.eurekaUrl}${this.config.instance.app}/${this.instanceId}`
url: `${this.eurekaUrl}${this.config.instance.app}/${this.instanceId}`
}, (error, response, body) => {
if (!error && response.statusCode === 200) {
this.logger.info('de-registered with eureka: ', `${this.config.instance.app}/${this.instanceId}`);
Expand All @@ -162,7 +167,7 @@ export class Eureka {

renew() {
request.put({
url: `${this.eurekaUrl}${this.config.instance.app}/${this.instanceId}`
url: `${this.eurekaUrl}${this.config.instance.app}/${this.instanceId}`
}, (error, response, body) => {
if (!error && response.statusCode === 200) {
this.logger.debug('eureka heartbeat success');
Expand Down

0 comments on commit c99857c

Please sign in to comment.