0.1.0-beta4 • Published 4 years ago

node-spring-cloud-config-client v0.1.0-beta4

Weekly downloads
17
License
UNLICENSED
Repository
-
Last release
4 years ago

node-spring-cloud-config-client

Node-spring-cloud-config-client is a typescript implementation of spring cloud config client for node js.

Build

Install

# with npm
npm install node-spring-cloud-config-client

# or with Yarn
yarn add node-spring-cloud-config-client

Usage

In your application, use init method to start the load of variables in your process.env

//typescript
import {PropertySourcesContext} from 'node-spring-cloud-config-client'

//javascript
const {PropertySourcesContext} = require('node-spring-cloud-config-client')

...
...
// When in your server want to retry configuration from spring cloud config server
const propertySourcesContext = PropertySourcesContext.getInstance()
propertySourcesContext.load()
.subscribe(result => ...);

// You can also await execution of load method
const propertySourcesContext = PropertySourcesContext.getInstance()
const result = await propertySourcesContext.load()
.toPromise()

...

After load method, you can access data from env with process.env:

const database_password = process.env['db.password']

Options

client configuration

Properties dictionary:

Property nameDefault value
NSCCC_BASE_URIhttp://localhost:8888
NSCCC_APPLICATION_NAMEapplication
NSCCC_PROFILE
NSCCC_LABEL

With the above properties, node-spring-cloud-config-client can perform the rest call to the correct spring cloud config server.

Based on properties will be create the rest call:

<NSCCC_BASE_URI>/<NSCCC_APPLICATION_NAME>/<NSCCC_PROFILE>/<NSCCC_LABEL>

Example:

NSCCC_BASE_URINSCCC_APPLICATION_NAMENSCCC_PROFILENSCCC_LABELRest call
http://localhost:8888/application/default
http://your.server/http://your.server/application/default
your-application-namehttp://localhost:8888/your-application-name/default
devhttp://localhost:8888/application/dev
labelhttp://localhost:8888/application/default/label
http://your.server/your-application-nameprodhttp://your.server/your-application-name/prod
http://your.server/your-application-nameprodlabelhttp://your.server/your-application-name/prod/label

fail strategy configuration

Properties dictionary:

Property nameDefault value
NSCCC_FAIL_FASTfalse
NSCCC_MAX_RETRY_ATTEMPTS6
NSCCC_SCALING_DURATION1000

You can specify what happen when call to propertie server fails.

If you want that when the call fails there are no error, set NSCCC_FAIL_FAST=false.

Otherwise, specify NSCCC_FAIL_FAST=true.

When NSCCC_FAIL_FAST not set 'true' or 'false', is like set NSCCC_FAIL_FAST to 'false'.

If NSCCC_FAIL_FAST set to true, is applied a retry that follow the properties NSCCC_MAX_RETRY_ATTEMPTS and NSCCC_SCALING_DURATION

With NSCCC_MAX_RETRY_ATTEMPTS specify how much times the retry will be performed.

With NSCCC_SCALING_DURATION specify what is scaling duration beetwen two retry.

Example:

export NSCCC_MAX_RETRY_ATTEMPTS=4
export NSCCC_SCALING_DURATION=500

Suppose that your config server is down and does not respond.

After the first call to config server, node-spring-cloud-config-client perform another call after 500 ms, after 1000 ms, after 1500 ms and after 2000 ms. After that node-spring-cloud-config-client emit error.

log configuration

Properties dictionary

Property nameDefault valueaccepted valueif not accepted value
NSCCC_LOGGER_ENABLEDfalsetrue/falseset to 'false'
NSCCC_LOGGER_LEVELerrordebug/info/errorset to 'error'

You may turn on/off the log with property NSCCC_LOGGER_ENABLED.

You can specify level log with property NSCCC_LOGGER_LEVEL.