@opuscapita/config
Advanced tools
Comparing version 3.0.10 to 3.0.11
@@ -203,2 +203,28 @@ const ConfigClientBase = require('./ConfigClientBase'); | ||
/** | ||
* Gets a list of endpoints from consul's service registry. | ||
* Be aware, that this method only returns service endpoints that are marked *healthy* by consul. | ||
* Endpoints that did not pass all health checks will not be available. | ||
* | ||
* This method uses retry in order to bypass problems with network connections, service latencies or | ||
* remote service capacity problems. For further details have a look at the [DefaultConfig]{@link DefaultConfig}. | ||
* @param {string} serviceName - Name of service to request. | ||
* @param {boolean} silent - If set to true, this method will not use retry to get something from consul so it will return faster and it will not pass any errors up to the calling code. | ||
* @returns {Promise} Returns a bluebird [Promise]{@link http://bluebirdjs.com/docs/api-reference.html} containing an array of [Endpoint]{@link module:ocbesbn-config~Endpoint} objects. | ||
*/ | ||
getEndPoints(serviceName, silent) | ||
{ | ||
if(Array.isArray(serviceName)) | ||
return Promise.all(serviceName.map(k => this.getEndPoints(k, silent))); | ||
const task = () => this._getConsulEndpoints(serviceName); | ||
if(silent) | ||
return task().catch(e => { this.logger.error(e); return [ ]; }); | ||
else | ||
return retry(task, { max_tries: this.config.retryCount, interval: this.config.retryTimeout }) | ||
.catch(e => { this.logger.error(e); throw e; }); | ||
} | ||
/** | ||
* Gets a single or a list of values from consul's key-value store. Alias for [getProperty()]{@link getProperty}. | ||
@@ -205,0 +231,0 @@ * To get a list of values you can either use key-prefixing or and array of keys and key-prefixes. |
@@ -167,3 +167,3 @@ const EventEmitter = require('events'); | ||
const mapService = (s) => ({ | ||
host : s.Service.ServiceAddress || s.Service.Address, | ||
host : s.Service.ServiceAddress || s.Service.Address || s.Node.Address, | ||
port : s.Service.Port, | ||
@@ -253,2 +253,7 @@ modifyIndex : s.Service.ModifyIndex | ||
{ | ||
return this._getRandomValueThrow(await this._getConsulEndpoints(serviceName)); | ||
} | ||
async _getConsulEndpoints(serviceName) | ||
{ | ||
const cacheName = this.serviceName + '.ep.' + serviceName; | ||
@@ -261,3 +266,11 @@ const results = await this.cache.get(cacheName); | ||
return retry(async () => this._getRandomValueThrow(await this.cache.get(cacheName)), { max_tries : 5, interval : 500 }) | ||
const getValuesOrThrow = async (values) => | ||
{ | ||
if(!values || (Array.isArray(values) && values.length === 0)) | ||
throw new Error('Could not get values.'); | ||
return values; | ||
} | ||
return retry(async () => getValuesOrThrow(await this.cache.get(cacheName)), { max_tries : 5, interval : 500 }) | ||
.catch(e => { throw new Error('The requested endpoint could not be found or did not pass health checks: ' + serviceName); }); | ||
@@ -267,3 +280,3 @@ } | ||
{ | ||
return this._getRandomValue(results); | ||
return results; | ||
} | ||
@@ -270,0 +283,0 @@ } |
{ | ||
"name": "@opuscapita/config", | ||
"version": "3.0.10", | ||
"version": "3.0.11", | ||
"description": "Configuration API connector module for OpusCapita Business Network Portal.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34120
584