grpc-client-egg

0.1.3 • Public • Published

grpc-client-egg

npm version

An egg grpc client written in Typescript.

How to use

1 install

npm i -S grpc-client-egg

2 include

import { EggPlugin } from 'egg'
 
const plugin: EggPlugin = {
 
    routerPlus: {
        enable: true,
        package: 'egg-router-plus',
    },
    grpcClient: {
        enable: true,
        package: 'grpc-client-egg',
    },
}
export default plugin
 

3 config

import { EggAppConfig, PowerPartial } from 'egg'
 
export default () => {
    const config: PowerPartial<EggAppConfig> = {
 
        grpcClient: {
            clients: [
                {
                    name: 'main',
                    protoPath: 'app/proto/main',
                    host: '0.0.0.0',
                    port: 50051,
                },
            ],
        },
    }
    return config
}

4 invoke promisified grpc service methods

import { Service } from 'egg'
 
export default class Greeter extends Service {
 
    readonly service: GreeterService = this.app.grpcClient.main.greeter.Greeter
 
    public async sayHello(name: string) {
        return this.service.sayHello({ name })
    }
 
    public async sayGoodbye(name: string) {
        return this.service.sayGoodbye({ name })
    }
}

Default config from the plugin

    loaderOption{
        keepCasetrue,
        longsString,
        enumsString,
        defaultstrue,
        oneofstrue,
    },
 
    clients[
        {
            name: 'main',
            protoPath: 'app/proto/main',
            host: '0.0.0.0',
            port: 50051,
        },
    ],

Readme

Keywords

none

Package Sidebar

Install

npm i grpc-client-egg

Weekly Downloads

1

Version

0.1.3

License

MIT

Unpacked Size

7.58 kB

Total Files

9

Last publish

Collaborators

  • xiaozhongliu