sofastack / sofa-rpc-node

SOFARPC Node is a high-performance, high-extensibility, production-level Nodejs RPC framework.
MIT License
611 stars 64 forks source link

feat: support gRPC #11

Closed gxcsoccer closed 6 years ago

gxcsoccer commented 6 years ago

Client

const path = require('path');
const protobuf = require('antpb');
const proto = protobuf.loadAll(path.join(__dirname, 'proto'));

const logger = console;
const { GRpcClient } = require('sofa-rpc-node').client;

const client = new GRpcClient({
  logger,
  proto,
});

async function test() {
  const consumer = client.createConsumer({
    interfaceName: 'helloworld.Greeter',
    serverHost: 'http://localhost:12200',
  });
  await consumer.ready();
  const r = await consumer.invoke('SayHello', [{ name: 'peter' }]);
  console.log(r);
}

test();

Server

const protobuf = require('antpb');
const path = require('path');
const proto = protobuf.loadAll(path.join(__dirname, 'proto'));

const logger = console;
const { GRpcServer } = require('sofa-rpc-node').server;

const server = new GRpcServer({
  logger,
  port: 12200,
  proto,
});

server.addService({
  interfaceName: 'helloworld.Greeter',
}, {
  async SayHello(req) {
    console.log(req);
    return {
      message: `hello ${req.name} from sofa-rpc-node`,
    };
  },
});

server.start();
mingcheng commented 6 years ago

Good Job,建议增加 Java 端(传统后端)的测试

gxcsoccer commented 6 years ago

Good Job,建议增加 Java 端(传统后端)的测试

用官方的示例即可 https://grpc.io/docs/quickstart/java.html

codecov-io commented 6 years ago

Codecov Report

Merging #11 into master will decrease coverage by 0.55%. The diff coverage is 96.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #11      +/-   ##
==========================================
- Coverage   98.91%   98.36%   -0.56%     
==========================================
  Files          30       38       +8     
  Lines        1295     1769     +474     
==========================================
+ Hits         1281     1740     +459     
- Misses         14       29      +15
Impacted Files Coverage Δ
lib/client/request.js 100% <ø> (ø) :arrow_up:
lib/client/consumer.js 100% <100%> (ø) :arrow_up:
lib/client/connection/rpc.js 100% <100%> (ø)
lib/client/connection_mgr.js 96.87% <100%> (ø) :arrow_up:
lib/client/connection/grpc/index.js 100% <100%> (ø)
lib/server/grpc/response.js 100% <100%> (ø)
lib/util/proto_util.js 100% <100%> (ø)
lib/client/grpc_client.js 100% <100%> (ø)
lib/client/client.js 100% <100%> (ø) :arrow_up:
lib/client/connection/grpc/metadata.js 100% <100%> (ø)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 56cb8b0...1a20bbe. Read the comment docs.

gxcsoccer commented 6 years ago

1.2.0