1.1.6 • Published 3 years ago

gioneco-grpc v1.1.6

Weekly downloads
1
License
ISC
Repository
github
Last release
3 years ago

gioneco-grpc

1.Install

npm install gioneco-grpc

2.Usage

server

import {GrpcServer, ServiceRegistry} from "gioneco-grpc"

const register = new ServiceRegistry({
  host: "127.0.0.1",
  port: 8500
});
const grpcServer = new GrpcServer({
  protosDir: `${process.cwd()}/protos`,
  serviceFunctionMap: {
    //package.function
    "helloworld.SayHello"(call, callback) {
      callback(null, {message: 'Hello ' + call.request.name});
    },
    "testing.UnaryCall"(call, callback){
      callback(null, {username: "test", oauth_scope:"test1"});
    },
  },
  registry:register,
  checkServerPort: 1338
})
grpcServer.ready();

client

import { GrpcClient, ServiceRegistry } from "gioneco-grpc";
const register = new ServiceRegistry({
  host: "127.0.0.1",
  port: "8500",
  promisify: true,
});
const grpcClient = new GrpcClient({
  protosDir: `${process.cwd()}/protos`,
  registry: register
})
function run() {
  const client = grpcClient.getGrpcClient("helloworld")
  const user = 'world111111111111';
  if (client) {
    client.sayHello({name: user}, function(err, response) {
      if (err) {
        throw err
      }
      console.log('Greeting:', response.message);
    });
  } else {
    throw new Error("无法获取grpc client")
  }
}
setTimeout(run, 500)

3.Service registration and discovery

gioneco-grpc uses consul to implement service registration and discovery

const register = new ServiceRegistry({
  host: "127.0.0.1", // consul host
  port: 8500 // consul port
});
1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.2

3 years ago

1.1.0

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago