4.1.0 • Published 7 months ago

@qiwi/nestjs-enterprise-consul v4.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 months ago

@qiwi/nestjs-enterprise-consul

Nestjs module for working with Consul

Installation

Requires following packages to be installed

yarn add @qiwi/nestjs-enterprise-consul

Configuration

import { Module } from '@nestjs/common'
import { ConfigModule } from '@qiwi/nestjs-enterprise-config'
import { LoggerModule } from '@qiwi/nestjs-enterprise-logger'
import { ConsulModule } from '@qiwi/nestjs-enterprise-consul'

@Module({
  imports: [
    ConfigModule,
    LoggerModule,
    ConsulModule,
    // and so on
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}

Config

{
  "data": {
    "name": "APP_NAME",
    "server": {
      "port": 8080,
      "host": "$host:"
    },
    "consul": {
      "host": "CONSUL_AGENT_HOST",
      "port": "CONSUL_AGENT_PORT",
      "token": "consul token",
      "tags": ["tag"]
    }
  },
  "sources": {
    "host": {
      "pipeline": "ip"
    }
  }
}

Usage

// main.ts
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'

async function bootstrap() {

  const app = await NestFactory.create(AppModule)
  //...
  
const consul = app.get('IConsul')
const local = config.get('local')
//...

  if (!local) {
    consul.register()
  }
}
 //...
// service.ts
@Injectable()
export class ConnectionProviderService implements IConnectionProvider {
  constructor(
    @Inject('IConsul')
    private consul: IConsul,
  ) {}

  async getConnectionParams(serviceName: string) {
    return this.consul.getConnectionParams(serviceName)
  }
}

API

ConsulModule class

Exports ConsulService with token IConsul

ConsulService class

register(opts: any): IPromise

getConnectionParams(opts: any): Promise<IConnectionParams | undefined>

fieldtypedescription
IConnectionParams.hoststringhost
IConnectionParams.portnumberport

getKv(opts: any): Promise \

fieldtypedescription
INormalizedConsulKvValue.createIndexnumbercreateIndex
INormalizedConsulKvValue.modifyIndexnumbermodifyIndex
INormalizedConsulKvValue.lockIndexnumberlockIndex
INormalizedConsulKvValue.keystringkey
INormalizedConsulKvValue.flagsnumberflags
INormalizedConsulKvValue.valuestringvalue

Docs

3.0.0

9 months ago

4.1.0

7 months ago

4.0.1

8 months ago

4.0.3

8 months ago

4.0.2

8 months ago

2.0.5

11 months ago

2.0.4

1 year ago

2.0.3

1 year ago

2.0.2

2 years ago

1.3.1

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.3.0

2 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago