# Getting started
Welcome to the developer documentation for gRPC, a language-neutral,
platform-neutral remote procedure call (RPC) system developed at Google.
This document introduces you to gRPC with a quick overview and a simple
Hello World example. You'll find more tutorials and reference docs in this repository - more documentation is coming soon!
<a name="quickstart"></a>
## Quick start
You can find quick start guides for each language, including installation instructions, examples, and tutorials here:
* [C++](https://github.com/grpc/grpc-common/tree/master/cpp)
* [Java](https://github.com/grpc/grpc-common/tree/master/java)
* [Go](https://github.com/grpc/grpc-common/tree/master/go)
* [Ruby](https://github.com/grpc/grpc-common/tree/master/ruby)
* [Node.js](https://github.com/grpc/grpc-common/tree/master/node)
* [Android Java](https://github.com/grpc/grpc-common/tree/master/java/android)
* [Python](https://github.com/grpc/grpc-common/tree/master/python/helloworld)
## What's in this repository?
The `grpc-common` repository contains documentation, resources, and examples
for all gRPC users. You can find examples and instructions specific to your
favourite language in the relevant subdirectory.
You can find out about the gRPC source code repositories in
[`grpc`](https://github.com/grpc/grpc). Each repository provides instructions
for building the appropriate libraries for your language.
## What is gRPC?
In gRPC a *client* application can directly call
methods on a *server* application on a different machine as if it was a
local object, making it easier for you to create distributed applications and
services. As in many RPC systems, gRPC is based around the idea of defining
a *service*, specifying the methods that can be called remotely with their
parameters and return types. On the server side, the server implements this
interface and runs a gRPC server to handle client calls. On the client side,
the client has a *stub* that provides exactly the same methods as the server.
<!--TODO: diagram-->
gRPC clients and servers can run and talk to each other in a variety of
environments - from servers inside Google to your own desktop - and can
be written in any of gRPC's [supported languages](#quickstart). So, for
example, you can easily create a gRPC server in Java with clients in Go,
Python, or Ruby. In addition, the latest Google APIs will have gRPC versions
of their interfaces, letting you easily build Google functionality into
your applications.
<a name="protocolbuffers"></a>
### Working with protocol buffers
By default gRPC uses *protocol buffers*, Google’s
mature open source mechanism for serializing structured data (although it
can be used with other data formats such as JSON). As you'll
see in our example below, you define gRPC services using *proto files*,
with method parameters and return types specified as protocol buffer message
types. You
can find out lots more about protocol buffers in the [Protocol Buffers
documentation](https://developers.google.com/protocol-buffers/docs/overview).
#### Protocol buffer versions
While protocol buffers have been available for open source users for some
time, our examples use a new flavour of protocol buffers called proto3,
which has a slightly simplified syntax, some useful new features, and supports
lots more languages. This is currently available as an alpha release in
Java, C++, Java_nano (Android Java), Python, and Ruby from [the protocol buffers Github
repo](https://github.com/google/protobuf/releases), as well as a Go language
generator from [the golang/protobuf Github repo](https://github.com/golang/protobuf), with more languages in development. Full documentation for proto3 is currently in development, but you can see
the major differences from the current default version in the [release notes](https://github.com/google/protobuf/releases).
In general, while you *can* use proto2 (the current default protocol buffers version), we recommend that you use proto3 with gRPC as it lets you use the full range of gRPC-supported languages, as well as avoiding compatibility
issues with proto2 clients talking to proto3 servers and vice versa.
<a name="hello"></a>
## Hello gRPC!
Now that you know a bit more about gRPC, the easiest way to see how it
works is to look at a simple example. Our Hello World walks you through the
construction of a simple gRPC client-server application, showing you how to:
- Create a protocol buffers schema that defines a simple RPC service with
a single
Hello World method.
- Create a Java server that implements this interface.
- Create a Java client that accesses the Java server.
- Create a Go client that accesses
the same Java server.
The complete code for the example is available in the `grpc-common` GitHub
repository. We use the Git versioning system for source code management:
however, you don't need to know anything about Git to follow along other
than how to install and run a few git commands.
This is an introductory example rather than a comprehensive tutorial, so
don't worry if you're not a Go or
Java developer - the concepts are similar for all languages, and you can
find more implementations of our Hello World example in other languages (and full tutorials where available) in
the [language-specific folders](#quickstart) in this repository. Complete tutorials and
reference documentation for all gRPC languages are coming soon.
<a name="setup"></a>
### Setup
This section explains how to set up your local machine to work with
the example code. If you just want to read the example, you can go straight
to the [next step](#servicedef).
#### Install Git
You can download and install Git from http://git-scm.com/download. Once
installed you should have access to the git command line tool. The main
commands that you will need to use are:
- git clone ... : clone a remote repository onto your local machine
- git checkout ... : check out a particular branch or a tagged version of
the code to hack on
#### Install gRPC
To build and install gRPC plugins and related tools:
- For Java, see the [Java quick start](https://github.com/grpc/grpc-java).
- For Go, see the [Go quick start](https://github.com/grpc/grpc-go).
#### Get the source code
The example code for our Java example lives in the `grpc-java`
GitHub repository. Clone this repository to your local machine by running the
following command:
```
git clone https://github.com/google/grpc-java.git
```
Change your current directory to grpc-java/examples
```
cd grpc-java/examples
```
<a name="servicedef"></a>
### Defining a service
The first step in creating our example is to define a *service*: an RPC
service specifies the methods that can be called remotely with their parameters
and return types. As you saw in the
[overview](#protocolbuffers) above, gRPC does this using [protocol
buffers](https://developers.google.com/protocol-buffers/docs/overview). We
use the protocol buffers interface definition language (IDL) to define our
service methods, and define the parameters and return
types as protocol buffer message types. Both the client and the
server use interface code generated from the service definition.
Here's our example service definition, defined using protocol buffers IDL in
[helloworld.proto](https://github.com/grpc/grpc-java/tree/master/examples/src/main/proto). The `Greeting`
service has one method, `hello`, that lets the server receive a single
`HelloRequest`
message from the remote client containing the user's name, then send back
a greeting in a single `HelloReply`. This is the simplest type of RPC you
can specify in gRPC - we'll look at some other types later in this document.
```proto
syntax = "proto3";
option java_package = "io.grpc.examples";
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;
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
In gRPC a client application can directly call methods on a server application on a different machine as if it was a local object, making it easier for you to create distributed applications and services. As in many RPC systems, gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters and return types. On the server side, the server implements this interface and runs a gRPC server to handle client calls. On the client side, the client has a stub that provides exactly the same methods as the server.
资源推荐
资源详情
资源评论
收起资源包目录
grpc-common-master.zip (93个子文件)
grpc-common-master
node
route_guide
route_guide_server.js 8KB
route_guide_client.js 7KB
route_guide.proto 4KB
route_guide_db.json 13KB
README.md 17KB
package.json 171B
helloworld.proto 2KB
greeter_client.js 2KB
.gitignore 29B
README.md 1KB
greeter_server.js 2KB
cpp
route_guide
helper.h 2KB
route_guide_server.cc 7KB
route_guide_db.json 13KB
route_guide_client.cc 9KB
helper.cc 5KB
Makefile 4KB
cpptutorial.md 20KB
README.md 2KB
helloworld
greeter_client.cc 3KB
greeter_server.cc 3KB
Makefile 4KB
README.md 3KB
python
route_guide
route_guide.proto 4KB
run_codegen.sh 204B
route_guide_pb2.py 12KB
run_server.sh 272B
route_guide_db.json 13KB
run_client.sh 272B
route_guide_client.py 5KB
.gitignore 6B
route_guide_resources.py 2KB
route_guide_server.py 5KB
helloworld
run_codegen.sh 203B
run_server.sh 266B
helloworld.proto 2KB
run_client.sh 265B
helloworld_pb2.py 5KB
.gitignore 6B
greeter_server.py 2KB
README.md 3KB
greeter_client.py 2KB
LICENSE 1KB
PATENTS 1KB
go
gotutorial.md 21KB
greeter_client
main.go 2KB
greeter_server
main.go 2KB
README.md 1KB
helloworld
helloworld.pb.go 3KB
ruby
grpc-demo.gemspec 714B
greeter_server.rb 2KB
route_guide
route_guide_client.rb 5KB
route_guide_server.rb 7KB
README.md 14KB
greeter_client.rb 2KB
Gemfile 359B
.gitignore 125B
lib
route_guide_services.rb 679B
route_guide.rb 1KB
helloworld_services.rb 522B
helloworld.rb 571B
README.md 2KB
.gitignore 99B
grpc-auth-support.md 7KB
java
android
gradlew.bat 2KB
gradlew 5KB
app
proguard-rules.pro 659B
src
main
res
mipmap-hdpi
ic_launcher.png 3KB
values
strings.xml 84B
mipmap-xxhdpi
ic_launcher.png 8KB
mipmap-mdpi
ic_launcher.png 2KB
mipmap-xhdpi
ic_launcher.png 5KB
layout
activity_helloworld.xml 2KB
java
io
grpc
helloworldexample
GreeterGrpc.java 7KB
Helloworld.java 6KB
HelloworldActivity.java 3KB
AndroidManifest.xml 785B
.gitignore 7B
build.gradle 971B
gradle
wrapper
gradle-wrapper.jar 49KB
gradle-wrapper.properties 232B
.gitignore 202B
README.md 1KB
settings.gradle 15B
build.gradle 457B
javatutorial.md 25KB
README.md 1KB
protos
route_guide.proto 4KB
hellostreamingworld.proto 2KB
helloworld.proto 2KB
README.md 179B
PROTOCOL-HTTP2.md 11KB
README.md 17KB
共 93 条
- 1
资源评论
Kinonoyomeo
- 粉丝: 74
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 111111111111111111
- Screenshot_2024-04-30-21-47-24-26.jpg
- Cpp1.cpp1111111111
- 利用ERP流程操作的整个订单流程.ppt
- 最新二开版本源码博客论坛源码,UI很漂亮,可切换皮肤界面.rar
- ModStartBlog现代化个人博客系统 v5.2.0源码.rar
- 带posix库的mingw编译器
- SoraAI是一款功能强大的AI助手,由OpenAI开发,以其出色的语音识别技术、广泛的知识库和高度的人工智能特性而备受瞩目
- Thinkphp开发大气响应式个人博客青春博客网站源码.rar
- 最新PHP博客网站程序源码 ThinkPHP.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功