@tick-core/grpc-server

0.0.9 • Public • Published

tick-core-grpc-server: grpc server

下载

npm install @tick-core/grpc-server

controller

import {
  Controller,
  Router,
} from '@tick-core/grpc-server'

@Controller('testOne') // proto 的 package
export default class {
  @Router()   // or @Router('sayHello') proto service 中的 rpc method
  sayHello (data: any) {
    console.log(data)
    return {
      id: 13,
      name: '张思',
      age: 14
    }
  }
}

使用方式1【本地proto】

import {
  createGrpcServer,
} from '@tick-core/grpc-server'
import path from 'path'

createGrpcServer({
  ports: [8899, 8888],  // 多个端口会启用多个子进程,充分利用cpu资源
  controllerPath: path.join(__dirname, './controller'),
  protoPath:  path.join(__dirname, './protos'),
  logPath: '/xxx/xxx/xxx',
  backPath: '/xxx/xxx/xxx',
})

使用方式2【zookeeper proto】

import {
  createGrpcServer,
} from '@tick-core/grpc-server'
import path from 'path'
import {
  Zconf,
} from '@tick-core/zconf'

createGrpcServer({
  ports: [8899, 8888],
  controllerPath: path.join(__dirname, './controller'),
  protoPath: new Zconf({
    zookeeperConfs: [{
      host: '127.0.0.1',
      port: 2181,
    }],
    conf: {
      proto1: '/app/proto1',
      proto: '/app/proto'
    },
    retries: 3,
    cache: false,
  }),
  logPath: '/xxx/xxx/xxx',
  backPath: '/xxx/xxxxx',
})

Readme

Keywords

none

Package Sidebar

Install

npm i @tick-core/grpc-server

Weekly Downloads

0

Version

0.0.9

License

ISC

Unpacked Size

61.3 kB

Total Files

48

Last publish

Collaborators

  • xiaodong.han