Go GRPC Configuration

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

Recently, when studying the source code of Docker, when I read the libcontainerd part, I found that it used grpc. But previously only known as a library for RPC in distributed systems. Take this opportunity to learn about this tool.

Friends who have written WSDL in Java will feel that they are actually very similar in use.

Installing PROTOBUF 3

Because GRPC relies on protobuf, it transforms the service definition we wrote into a go file. So we need to install the PROTOBUF.

So why install Protobuf 3 This new, all aspects are not very well-developed version of it? The official web site recommends this version to install this version. If we install PROTOBUF2, we will likely have compatibility issues later.

How to install it?

First, go to Protobuf's GitHub home page to download the latest version of the PROTOBUF package. When I write this article, the most new version is 3.0.2. Here because we are configured for go, so we choose Protobuf-cpp-3.0.2.tar.gz This package to download. There is a clear description on the go support for Protocol buffers.

After the download is complete, we also need to compile the installation. Use the following command:

Tar zxvf protobuf-cpp-3.0.2.tar.gz
CD protobuf-cpp-3.0.2
./configure
Make install

You should then use the protoc--version command to see the corresponding version number. Here I am libprotoc 3.0.0. If you do not see it, and you are prompted for the Error while loading shared Libraries:libprotobuf.so.10:cannot open Shared object file:no such file or directory. That congratulation, you have the same egg as me. its We just need to install Libprotoc to solve the problem. Execute the following command:
sudo apt-get install libprotobuf-c0

Configuration Items

In addition, we also need to get protobuf packages in the project. Use this command:
Go get-u github.com/golang/protobuf/{proto,protoc-gen-go}

So we get the package that is related to protobuf . We also need to get the GRPC package:
Go get Google.golang.org/grpc

Friends also know that in the country, visit the products of Google Home, GFW will not let you so smooth. Google's Docker image warehouse Gcr.io be GFW wall, and Golang's package warehouse google.golang.org was GFW wall again. So, you're probably not going to succeed in executing that command.

So what's the good of this?


Give you a picture of your own experience it.

I recommend that you use the shadowsocks of this way. Then with the Polipo, the socks5 Proxy is converted to an HTTP proxy for flipping the wall.

In Ubuntu, the SOCKS5 is typically set to an HTTP proxy directly by following the two commands:

Export http_proxy=socks5://localhost:1080
Export https_proxy=socks5://localhost:1080

However, when we use go get to install the package in this way, we always fail. So we need to convert the SOCKS5 proxy to an HTTP proxy.

Test success or not

If you do not have an error in the above steps, then you should be successful ...

Do you believe it?

I don't believe it anyway.

Practice is the only standard to test truth!!

We go into the google.golang.org_1/grpc/examples/helloworld/ directory and we can see that there are two subdirectories:greeter_client and Greeter_server. We go into the greeter_server and execute go run main.go, and in the right case, no output will be seen.

Then, open a new terminal, enter into the greeter_client , enter go run main.go, will output: current time + Greeting:hello world .

Summarize

If you have any other errors, please Google yourself. Anyway, the mistake I encountered in this article has already told you.

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.