UNPKG

consul-balancer

Version:
37 lines (36 loc) 1.53 kB
import Consul from 'consul'; import * as urllib from 'urllib'; import * as grpc from '@grpc/grpc-js'; import type { ConsulOptions, RegisterOptions, Service } from './types'; export declare class ConsulBalancer { private options; private address; private serviceRegisterId; private cachedServices; private conculInstance; private static defaultOptions; constructor(port: number, host: string, options: ConsulOptions); constructor(port: number, options: ConsulOptions); constructor(port: number, host: string); constructor(options: ConsulOptions); constructor(port: number); constructor(host: string); constructor(); getConsulInstance(): Consul.Consul; register(options?: RegisterOptions): Promise<never>; deregister(serviceId?: string): Promise<unknown>; /** * grpc load balancer * @param serviceName - name of the service | address:port * @param targe - grpc client instance target * @param method - grpc method name * @param data - grpc request data */ grpc(serviceName: string, target: grpc.ServiceClientConstructor, method: string, data: unknown): Promise<unknown>; rest(serviceName: string, pathName: string, options?: urllib.RequestOptions2): Promise<urllib.HttpClientResponse<any>>; getPassingServiceByRandom(serviceName?: string): Promise<Service | null | undefined>; private getServiceListFromConsul; private parseOptions; private getServiceRegisterId; private findFirstNonLoopbackHostInfo; }