Skip to content

zcong1993/grpc-etcd-resolver

Repository files navigation

grpc-etcd-resolver

NPM version NPM downloads

etcd resolver for @grpc/grpc-js

Install

$ yarn add @zcong/grpc-etcd-resolver
# or npm
$ npm i @zcong/grpc-etcd-resolver --save

Usage

server

const serviceName = 'test'

const main = async () => {
  const server = new grpc.Server()
  server.addService(HelloService, helloServer)

  const addr = `0.0.0.0:${process.env.PORT ?? '8080'}`

  const etcd = new Etcd3()

  // register service addr to etcd
  register(etcd, serviceName, addr)

  server.bindAsync(addr, grpc.ServerCredentials.createInsecure(), () => {
    server.start()
  })
}

client

const serviceName = 'test'

const main = async () => {
  const etcd = new Etcd3()
  // setup etcd resolver
  setupEtcdResolver(etcd)

  const c = new HelloClient(
    `${EtcdScheme}:///${serviceName}`, // use service name with EtcdScheme
    grpc.credentials.createInsecure(),
    { 'grpc.service_config': '{"loadBalancingConfig": [{"round_robin": {}}]}' } // use round_robin lb
  )
}

License

MIT © zcong1993

About

etcd resolver for @grpc/grpc-js

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •