diff --git a/lib/serviceDiscovery/engines/consul/index.js b/lib/serviceDiscovery/engines/consul/index.js index 40436e71..06a991a8 100644 --- a/lib/serviceDiscovery/engines/consul/index.js +++ b/lib/serviceDiscovery/engines/consul/index.js @@ -89,20 +89,19 @@ class ConsulService extends Service { announce(port, metadata, cb) { logger.debug(`Announcing service ${this.name} on port ${port}`); this._announces.push({port, metadata}); - this.session((err, id) => { + this.session((err) => { if (err) { return cb(err); } - const key = [this.path, os.hostname(), process.pid].join('/'); + const key = [this.path, os.hostname(), helpers.generateId(port)].join('/'); this._consul.kv.set({ key, value: JSON.stringify({ port, ip: this._ip, data: metadata - }), - acquire: id + }) }, cb); }); } @@ -242,7 +241,7 @@ class ConsulService extends Service { logger.error.data(err).log(`Failed to renew session ${this._sessionId}`); } - this._keepaliveTimer = setTimeout(this._keepalive.bind(this, sessionId), this.ttl); + this._keepaliveTimer = setTimeout(this._keepalive.bind(this, sessionId), this.ttl / 2); }); }