-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,771 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.