How to use the @nestjs/microservices/client.ClientGrpcProxy function in @nestjs/microservices

To help you get started, weโ€™ve selected a few @nestjs/microservices examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nest-cloud / nestcloud / packages / grpc / grpc-client.ts View on Github external
private getProxyService(name: string, method: string): { service: T, node: IServer } {
        const lb: ILoadbalance = NestCloud.global.loadbalance;
        if (!lb) {
            return { service: null, node: null };
        }
        const node = lb.choose(this.config.service);
        const methodKey = `${node.id}/${method}`;
        if (!this.serviceCache.get(methodKey)) {
            if (!this.proxyCache.has(node.id)) {
                const proxy = new ClientGrpcProxy({
                    url: `${node.address}:${node.port}`,
                    package: this.config.package,
                    protoPath: this.config.protoPath,
                });
                this.proxyCache.set(node.id, proxy);
            }
            const proxy = this.proxyCache.get(node.id);
            const service = proxy.getService(name);
            this.serviceCache.set(methodKey, service);
        }

        const service = this.serviceCache.get(methodKey) as T;

        return { service, node };
    }
}
github nest-cloud / nestcloud / packages / grpc / grpc-client.ts View on Github external
constructor(config: IClientConfig) {
        this.config = config;
        this.proxy = new ClientGrpcProxy(config);
    }