Skip to content

Commit

Permalink
feat: support gRPC (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxcsoccer authored Sep 11, 2018
1 parent 56cb8b0 commit 9a94c21
Show file tree
Hide file tree
Showing 26 changed files with 1,771 additions and 25 deletions.
25 changes: 25 additions & 0 deletions example/grpc_client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

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

const logger = console;
const { GRpcClient } = require('../').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();
27 changes: 27 additions & 0 deletions example/grpc_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

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

const logger = console;
const GRpcServer = require('../lib/server/grpc/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();
38 changes: 38 additions & 0 deletions example/proto/helloworld.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2015 gRPC authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";

package helloworld;

// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
string name = 1;
}

// The response message containing the greetings
message HelloReply {
string message = 1;
}
2 changes: 1 addition & 1 deletion lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const assert = require('assert');
const Scheduler = require('./scheduler');
const RpcConsumer = require('./consumer');
const protocol = require('sofa-bolt-node');
const RpcConnection = require('./connection');
const RpcConnection = require('./connection/rpc');
const ConnectionManager = require('./connection_mgr');

const defaultOptions = {
Expand Down
Loading

0 comments on commit 9a94c21

Please sign in to comment.