[Golang GRPC] Framework Introduction

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Official website

http://www.grpc.io/

Http://www.grpc.io/docs/quickstart/go.html

GRPC Installation

Go Installation

Currently GRPC needs to be supported on go 1.5 or higher. Go installation can refer to: http://www.cnblogs.com/heartchord/p/5127503.html.

Protocol Buffer Installation

Protocol buffer and Go plug-in installation can refer to: http://www.cnblogs.com/heartchord/p/5337863.html.

GRPC Installation

Go get Google.golang.org/grpc

• Official Example Test

The GRPC package comes with a test example, and the path is google.golang.org/grpc/examples, and we use the HelloWorld project under the example to test it.

To compile the server and client:

Go install Google.golang.org\grpc\examples\helloworld\greeter_servergo Install google.golang.org\grpc\examples\ Helloworld\greeter_client

Turn on the two consoles to run Greeter_server.exe and Greeter_client.exe separately:

HelloWorld Engineering Analysis

.proto and. pb.go files

Using Protobuf you will know that no matter what project requires a. proto file to define the structure of the data, the file is Protoc.exe output to get the corresponding language source code files, for example, C + + get xxxx.pb.h and xxxx.pb.cc files. For the Golang, you need the above plug-in support, corresponding to get the Xxxx.pb.go file.

Official documents:

Https://developers.google.com/protocol-buffers/docs/proto3

Https://developers.google.com/protocol-buffers/docs/gotutorial

The Hellorequest and helloreply messages in the proto file are converted to the go language structure and some member functions are added automatically.

The Greeter service in the proto file will automatically generate Greeterclient and Greeterserver interfaces, where Greeterclient will have an internal type of greeterclient, Greeterclient defines the specific behavior of SayHello, while SayHello in greeterserver needs to be defined by itself.

The core point of SayHello specific behavior defined by Greeterclient is the SayHello function that invokes the server:

The service side needs to define the specific behavior of the SayHello:

pb.go File Generation command

// CD $GOPATH/src/google.golang.org/grpc/examples/helloworldprotoc-i helloworld/helloworld/ Helloworld.proto--go_out=plugins=grpc:helloworld

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.