0.7.1 • Published 4 years ago

@dimensionfourcloud/consul v0.7.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

NestCloud - Consul

Description

A NestCloud component for providing consul api based on node-consul.

中文文档

Installation

$ npm i --save @dimensionfourcloud/consul consul

Quick Start

Import Module

import { Module } from '@nestjs/common';
import { ConsulModule } from '@dimensionfourcloud/consul';
import { BootModule } from '@dimensionfourcloud/boot';
import { NEST_BOOT } from '@dimensionfourcloud/common';

@Module({
  imports: [
      BootModule.register(__dirname, 'bootstrap.yml'),
      ConsulModule.register({dependencies: [NEST_BOOT]})
  ],
})
export class ApplicationModule {}

Configurations

consul:
  host: localhost
  port: 8500

Usage

import { Injectable } from '@nestjs/common';
import * as Consul from 'consul';
import { InjectConsul } from '@dimensionfourcloud/consul';

@Injectable()
export class TestService {
  constructor(
    @InjectConsul() private readonly consul: Consul
  ) {
  }
}

Simple Get Consul KV

import { Injectable } from '@nestjs/common';
import { WatchKV } from '@dimensionfourcloud/consul';

@Injectable()
export class TestService {
  @WatchKV('test_key', 'yaml', {})
  private readonly config: any;
}

API

class ConsulModule

static register(options: Options): DynamicModule

Import nest consul module.

fieldtypedescription
options.dependenciesstring[]if you are using @dimensionfourcloud/boot module, please set NEST_BOOT
其他anysee node-consul

class Consul

see node-consul

Decorators

WatchKV(key: string, type?: 'json' | 'yaml' | 'text', defaults?: any): PropertyDecorator

Inject consul kv to the class attribute, it will update immediately when consul kv update.

Stay in touch

License

NestCloud is MIT licensed.