Consul module for the Hapiness framework.
To get started with consul, you can begin with having a look at the consul official documentation
- Using your module inside Hapiness application
- Using
Consulinside your hapiness application - Contributing
- Maintainers
- License
$ npm install --save @hapiness/core @hapiness/consul rxjs
or
$ yarn add @hapiness/core @hapiness/consul rxjs"dependencies": {"@hapiness/consul": "^1.0.0","@hapiness/core": "^1.5.1","rxjs": "^5.5.7",//...}//...You need to include ConsulModule in the imports section of your module definition.
@HapinessModule({version: '1.0.0',declarations: [/* your declarations */],providers: [/* your providers */],exports: [/* your exports */],imports: [ConsulModule/* other modules */]})exportclassMyModule{/* ... */}You need to inject the extension in bootstrap using setConfig to instantiate the module.
The config properties allowed for the extensions are defined like this:
exportinterfaceHapinessConsulClientOptions{scheme?: string;host?: string;port?: string;defaults?: {consistent?: boolean;dc?: string;stale?: boolean;token?: string;wait?: string;wan?: boolean;ctx?: NodeJS.EventEmitter;timeout?: number;};ca?: string;baseUrl?: string;}Then just do like this:
Hapiness.bootstrap(MyModule,[ConsulExt.setConfig({/* Put your config here */})]).catch(err=>done(err));This library is in fact a wrapper of the famous consul node library but wrap all its functions to returns rxjs Observable
You can see the doc by clicking here
We provide a wrapper called ConsulService exposing a clientgetter that will allow you to access the consul client.
classFooProvider{constructor(private_consul: ConsulService){}bar(): Observable<string>{// Getting a key from the KV client of consulreturnthis._consul.client.kv.get('hello');}acquireLock(): void{// Create a consul lockconstlock=this._consul.client.lock({key: 'test'});// Listen to lock eventslock.on('acquire',()=>{console.log('lock acquired'));lock.release();});lock.on('release',()=>console.log('lock released'));lock.on('error',()=>console.log('lock error:',err));lock.on('end',(err)=>console.log('lock released or there was a permanent failure'));// Acquire the locklock.acquire();}}To set up your development environment:
- clone the repo to your workspace,
- in the shell
cdto the main folder, - hit
npm or yarn install, - run
npm or yarn run test.- It will lint the code and execute all tests.
- The test coverage report can be viewed from
./coverage/lcov-report/index.html.
| Julien Fauville | Antoine Gomez | Sébastien Ritz | Nicolas Jessel |
Copyright (c) 2018 Hapiness Licensed under the MIT license.

