-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
105 additions
and
5 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
File renamed without changes
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,75 @@ | ||
# How to use gRPC | ||
|
||
[Reference Link](https://github.com/grpc/grpc-go/blob/master/examples/gotutorial.md) | ||
|
||
## Steps | ||
|
||
###1. Defining the service | ||
|
||
Define a service within file *route_guide.proto*. | ||
|
||
Syntax: | ||
|
||
```protobuf | ||
// Interface exported by the server. | ||
service RouteGuide { | ||
// you could place 'string' before a type | ||
rpc GetFeature(Point) returns (Feature) {} | ||
} | ||
message Point { | ||
int32 latitude = 1; | ||
int32 longitude = 2; | ||
} | ||
message Feature { | ||
string name = 1; | ||
Point location = 2; | ||
} | ||
``` | ||
|
||
### 2. Generating client and server code | ||
|
||
You could do this using the **protobuf compiler** `protoc` with a special gRPC **go plugin**. | ||
|
||
```shell | ||
[root@k8s-1 tmp]# protoc --go_out=plugins=grpc:. route_guide.proto | ||
[root@k8s-1 tmp]# ls | ||
route_guide.proto route_guide.pb.go | ||
``` | ||
|
||
### 3. Handle the server | ||
|
||
First, implement the generated interface. | ||
|
||
Then, build and start the server: | ||
|
||
```reStructuredText | ||
1. Specify the port we want to use to listen for client requests; | ||
2. Create a instance of the gRPC server; | ||
3. Register our service implementation with the gRPC server; | ||
4. Call Serve() on the server with our port details to do a blocking wait until the process is killed or Stop() is called. | ||
``` | ||
|
||
### 4. Handle the client | ||
|
||
First, create a stub. | ||
|
||
```text | ||
1. Create a gRPC channel to communicate with the server; | ||
2. Once the gRPC channel is setup, we need a client stub to perform RPCs; | ||
``` | ||
|
||
Note that, in gRPC-go, RPCs operate in a blocking/synchronous mode. | ||
|
||
### 5. Try it out | ||
|
||
```text | ||
1. Start the server; | ||
2. Start the client to try it our. | ||
``` | ||
|
||
|
||
|
||
|
||
|
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
File renamed without changes
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,21 @@ | ||
# protocol buffer | ||
|
||
[Reference link](https://developers.google.com/protocol-buffers/docs/overview) | ||
|
||
## Introduction | ||
|
||
*protocol buffers* is a language-neutral, platform-neutral, extensible way of **serializing structured data**. | ||
|
||
Develops could use *protocol buffers* in their applications. | ||
|
||
*protocol buffers* is a **data format**, google's **data interchange format**. | ||
|
||
## Qustions | ||
|
||
- Why *protocol buffer* are faster than *xml*? | ||
|
||
- How *protocol buffer* messages are encoded? | ||
> [protocol buffer encoding](https://developers.google.com/protocol-buffers/docs/encoding) | ||
- What's the major differences between *proto3* and *proto2*? | ||
|
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