设为首页 加入收藏

TOP

The .NET World——gPRC概览(一)
2019-09-17 15:43:13 】 浏览:26
Tags:The .NET World gPRC 概览

什么是gRPC

官方的定义:

gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services.

gRPC是一种现代化开源的高性能RPC框架,能够运行于任意环境之中。它可以高效地在服务和数据中心内部与其间建立连接,并且可支持负载均衡,追踪,健康检测与认证功能。同时它也可用于分布式计算的“最后一公里”,连接设备,移动应用和浏览器到后端服务。

维基的定义:

gRPC (gRPC Remote Procedure Calls) is an open source remote procedure call (RPC) system initially developed at Google. It uses HTTP/2 for transport, Protocol Buffers as the interface description language, and provides features such as authentication, bidirectional streaming and flow control, blocking or nonblocking bindings, and cancellation and timeouts. It generates cross-platform client and server bindings for many languages. Most common usage scenarios include connecting services in microservices style architecture and connect mobile devices, browser clients to backend services.

gRPC(gRPC远程过程调用)是一种开源的远程过程调用系统,最初由谷歌进行开发。它使用HTTP/2作为传输协议。Protocol Buffer被用于接口描述语言,提供了诸如认证,双向流控制,阻塞或非阻塞绑定,取消与超时功能。它为多种语言生成跨平台的客户端与服务端绑定。最通用的使用场景包括在微服务样式架构中连接服务,以及连接移动设备,浏览器客户端到后端服务。

什么是RPC

从上面的解释里不难看出,要对gRPC有更直观的理解,首先需要明白RPC的定义。

继续看下维基上的内容:

In distributed computing, a remote procedure call (RPC) is when a computer program causes a procedure (subroutine) to execute in a different address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction. That is, the programmer writes essentially the same code whether the subroutine is local to the executing program, or remote. This is a form of client–server interaction (caller is client, executor is server), typically implemented via a request–response message-passing system. In the object-oriented programming paradigm, RPC calls are represented by remote method invocation (RMI). The RPC model implies a level of location transparency, namely that calling procedures is largely the same whether it is local or remote, but usually they are not identical, so local calls can be distinguished from remote calls. Remote calls are usually orders of magnitude slower and less reliable than local calls, so distinguishing them is important.

在分布式计算里,当计算机程序要运行一段代码,远程过程调用(RPC)会在不同的内存地址(一般是在网络里的不同计算机)上执行它。其无需程序员显示地对它的远程交互进行具体编码,编写代码的方式就如同一段普通的本地过程调用一般。即是,程序员所需写的代码是相同的,无论其调用的过程是在本地还是远程。这是一种客户端-服务端交互的形式(调用方是客户端,执行方是服务端),典型的实现方式是通过一种请求-响应的传递消息系统。在面向对象程序范式里,RPC调用被表示为远程方式调用(RMI)。RPC模型意味着一定程度的本地透明性,本地或是远程的调用过程大致而言是等同的,但又不是完全一样。远程调用通常比本地调用慢上几个数量级,同时也更加不可靠。

Remoting,Web Service,WCF

如果对RPC的概念还是理解不了的话,却曾使用过或者了解过诸如Remoting,Web Service或者WCF等技术的话,那么其实在这方面已经入门了。

Protocol buffers

Protocol buffers是谷歌开发的一套无关开发语言,无关平台的用于序列化结构数据的可扩展机制。它的用途与XML,JSON相同,但比它们更小,更快,更简洁。

作为gRPC中默认的接口定义语言,其既可以用于定义服务接口,也可以定义所必要的数据结构。

service HelloService {
  rpc SayHello (HelloRequest) returns (HelloResponse);
}

message HelloRequest {
  string greeting = 1;
}

message HelloResponse {
  string reply = 1;
}

Protocol buffers的代码需要保存在扩展名为.proto的文件之中。

服务类型

gRPC支持四种服务类型:

  1. 一元式RPC
  2. 服务端流式RPC
  3. 客户端流式RPC
  4. 双向流式RPC

一元式RPC,如同普通的方法调用一般,客户端的单一请求,至服务端后,返回唯一的响应。

rpc SayHe
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇(二十三)c#Winform自定义控件-.. 下一篇使用 .NET CORE 创建 项目模板,..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目