UNPKG

whale-nest-nacos

Version:

If you are a nest micro service architecture, you can use the SDK, so as to realize service discovery based on nacos, distributed load balancing strategy

88 lines (87 loc) 2.36 kB
/// <reference types="node" /> import { ClientGrpc } from '@nestjs/microservices'; import { Logger, LoggerService } from '@nestjs/common'; import { GrpcOptions } from '@nestjs/microservices'; import { ClientOptions } from 'nacos'; export declare enum Mode { Config = "Config", Pods = "Pods", Mock = "Mock" } export interface whaleNacosOptions extends LoadBalanceServiceOptions { mode?: keyof typeof Mode; localEnvString?: string; localhost?: string; } export interface BaseNacosClientOptions { serverAddress: string; namespace: string; logger: Logger | LoggerService | Console; endpoint: ClientOptions['endpoint']; } export interface DiscoveryOptions extends BaseNacosClientOptions { protocol?: string; group?: string; serviceName?: string; } export interface NacosClientOptions { serverAddress: string; namespace: string; logger: Logger | LoggerService | Console; } export interface NacosGrpcOptions extends Omit<GrpcOptions["options"], 'url' | 'package'> { packageName: GrpcOptions["options"]["package"]; } export interface LoadBalanceServiceOptions extends NacosGrpcOptions { group?: string; serviceName: string; loadBalance?: (arg0: Connection[]) => Connection; } export interface loggerOptions { loggerLevel?: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR'; logger?: Logger | LoggerService; } export interface NacosInstance { instanceId?: string; clusterName?: string; serviceName?: string; ip: string; port?: number; weight: number; ephemeral?: boolean; enabled?: boolean; valid?: boolean; marked?: boolean; healthy?: boolean; metadata?: any; } export interface NacosInstanceOptions { namespace?: string; serviceName: string; clusterName?: string; groupName?: string; ip?: string; port: number; weight?: number; valid?: boolean; healthy?: boolean; enabled?: boolean; ephemeral?: boolean; metadata?: any; } export interface NacosConfigOptions { group?: string; serviceName: string; } export interface Connection { grpcClient: ClientGrpc; weight: number; } export interface TierConfig { service_name: string; tier_version: string; } export interface NacosClientGrpc { getService<T>(name: string): T; } export declare type AllowUndefined<T> = T | undefined;