转载:https://blog.csdn.net/weiwangchao_/article/details/82023191
概述
gRPC 一开始由 google 开发,是一款语言中立、平台中立、开源的远程过程调用(RPC)系统。
在 gRPC 里客户端应用可以像调用本地对象一样直接调用另一台不同的机器上服务端应用的方法,使得您能够更容易地创建分布式应用和服务。与许多 RPC 系统类似,gRPC 也是基于以下理念:定义一个服务,指定其能够被远程调用的方法(包含参数和返回类型)。在服务端实现这个接口,并运行一个 gRPC 服务器来处理客户端调用。在客户端拥有一个存根能够像服务端一样的方法。
特性
- 基于HTTP/2
HTTP/2 提供了连接多路复用、双向流、服务器推送、请求优先级、首部压缩等机制。可以节省带宽、降低TCP链接次数、节省CPU,帮助移动设备延长电池寿命等。gRPC 的协议设计上使用了HTTP2 现有的语义,请求和响应的数据使用HTTP Body 发送,其他的控制信息则用Header 表示。 - IDL使用ProtoBuf
gRPC使用ProtoBuf来定义服务,ProtoBuf是由Google开发的一种数据序列化协议(类似于XML、JSON、hessian)。ProtoBuf能够将数据进行序列化,并广泛应用在数据存储、通信协议等方面。压缩和传输效率高,语法简单,表达力强。 - 多语言支持(C, C++, Python, PHP, Nodejs, C#, Objective-C、Golang、Java)
gRPC支持多种语言,并能够基于语言自动生成客户端和服务端功能库。目前已提供了C版本grpc、Java版本grpc-java 和 Go版本grpc-go,其它语言的版本正在积极开发中,其中,grpc支持C、C++、Node.js、Python、Ruby、Objective-C、PHP和C#等语言,grpc-java已经支持Android开发。
gRPC已经应用在Google的云服务和对外提供的API中,其主要应用场景如下:
- 低延迟、高扩展性、分布式的系统
- 同云服务器进行通信的移动应用客户端
- 设计语言独立、高效、精确的新协议
- 便于各方面扩展的分层设计,如认证、负载均衡、日志记录、监控等
HTTP2.0 特性
HTTP/2,也就是超文本传输协议第2版,不论是1还是2,HTTP的基本语义是不变的,比如方法语义(GET/PUST/PUT/DELETE),状态码(200/404/500等),Range Request,Cacheing,Authentication、URL路径, 不同的主要是下面几点:
多路复用 (Multiplexing)
在 HTTP/1.1 协议中 「浏览器客户端在同一时间,针对同一域名下的请求有一定数量限制。超过限制数目的请求会被阻塞」。
HTTP/2 的多路复用(Multiplexing) 则允许同时通过单一的 HTTP/2 连接发起多重的请求-响应消息。
因此 HTTP/2 可以很容易的去实现多流并行而不用依赖建立多个 TCP 连接,HTTP/2 把 HTTP 协议通信的基本单位缩小为一个一个的帧,这些帧对应着逻辑流中的消息。并行地在同一个 TCP 连接上双向交换消息。
二进制帧
HTTP/2 传输的数据是二进制的。相比 HTTP/1.1 的纯文本数据,二进制数据一个显而易见的好处是:更小的传输体积。这就意味着更低的负载。二进制的帧也更易于解析而且不易出错,纯文本帧在解析的时候还要考虑处理空格、大小写、空行和换行等问题,而二进制帧就不存在这个问题。
首部压缩(Header Compression)
HTTP是无状态协议。简而言之,这意味着每个请求必须要携带服务器需要的所有细节,而不是让服务器保存住之前请求的元数据。因为http2没有改变这个范式,所以它也需要这样(携带所有细节),因此 HTTP 请求的头部需要包含用于标识身份的数据比如 cookies,而这些数据的量也在随着时间增长。每一个请求的头部都包含这些大量的重复数据,无疑是一种很大的负担。对请求头部进行压缩,将会大大减轻这种负担,尤其对移动端来说,性能提高非常明显。
HTTP/2 使用的压缩方式是 HPACK。 http://http2.github.io/http2-spec/compression.html
HTTP2.0在客户端和服务器端使用“首部表”来跟踪和存储之前发送的键-值对,对于相同的数据,不再通过每次请求和响应发送;通信期间几乎不会改变的通用键-值对(用户代理、可接受的媒体类型,等等)只需发送一次。
事实上,如果请求中不包含首部(例如对同一资源的轮询请求),那么首部开销就是零字节。此时所有首部都自动使用之前请求发送的首部。
如果首部发生变化了,那么只需要发送变化了数据在Headers帧里面,新增或修改的首部帧会被追加到“首部表”。首部表在 HTTP2.0的连接存续期内始终存在,由客户端和服务器共同渐进地更新。
服务端推送(Server Push)
HTTP/2 的服务器推送所作的工作就是,服务器在收到客户端对某个资源的请求时,会判断客户端十有八九还要请求其他的什么资源,然后一同把这些资源都发送给客户端,即便客户端还没有明确表示它需要这些资源。
客户端可以选择把额外的资源放入缓存中(所以这个特点也叫 Cache push),也可以选择发送一个 RST_STREAM frame 拒绝任何它不想要的资源。
主动重置链接
Length的HTTP消息被送出之后,我们就很难中断它了。当然,通常我们可以断开整个TCP链接(但也不总是可以这样),但这样导致的代价就是需要重新通过三次握手建立一个新的TCP连接。
HTTP/2 引入了一个 RST_STREAM frame 来让客户端在已有的连接中发送重置请求,从而中断或者放弃响应。当浏览器进行页面跳转或者用户取消下载时,它可以防止建立新连接,避免浪费所有带宽。
与其他rpc比较
与thrift,dubbo,motan等比较
* | Motan | Dubbox | thrift | gRPC | rpcx |
---|---|---|---|---|---|
开发语言 | Java | Java | 跨语言 | 跨语言 | go |
分布式服务治理 | Y | Y | 可以配合zookeeper, Eureka等实现 | 可以配合etcd(go),zookeeper,consul等实现 | 自带服务注册中心,也支持zookerper,etcd等发现方式 |
底层协议 | motan协议,使用tcp长连接 | Dubbo 协议、 Rmi 协议、 Hessian 协议、 HTTP 协议、 WebService 协议、Dubbo Thrift 协议、Memcached 协议 | tpc/http/frame | http2 | tcp长链接 |
消息序列化 | hessian2,json | hessian2,json,resr,kyro,FST等,可扩展protobuf等 | thrift | protobuf | Gob、Json、MessagePack、gencode、ProtoBuf等 |
跨语言编程 | N(支持php client和c server) | N | Y | Y | N |
负载均衡 | ActiveWeight 、Random 、 RoundRobin 、LocalFirst 、 Consistent 、ConfigurableWeight | Random 、RoundRobin 、ConsistentHash 、 LeastActive | Haproxy, zookerper+客户端负载均衡等方案 | 负载均衡软件HaProxy等 | 支持随机请求、轮询、低并发优先、一致性 Hash等 |
容错 | Failover 失效切换、Failfast 快速失败 | Failover 、 Failfast 、Failsafe 、 Failback 、 Forking、 Broadcast | Failover | 具有 Failover 失效切换的容错策略 | 失败重试(Failover)、快速失败(Failfast) |
注册中心 | consul | zookeeper | zookeeper | etcd,zookeeper,consul | zookerper,etcd |
性能 | ★★ | ★★ | ★★★★ 比grpc快2-5倍 | ★★★ 比dubbox,motan快 | ★★★★★ 比thrift快1-1.5倍 |
侧重优势 | 服务管理 | 服务管理 | 跨语言,性能++ | 跨语言,性能 | 性能++,服务治理 |
客户端异步调用方案 |
| stream传输,双向通信 | |||
服务端异步处理 | 1、TNonblockingServer(java/c++,php); THsHaServer(java/c++); TThreadpoolServer(java/c++); TThreadSelectorServer(java/c++) 2、结合消息队列或中间件 3、swoole/goroutine等多任务支持 | 同上,使用stream传输。Stream对象在传输过程中会被当做集合,用Iterator来遍历处理 |
grpc vs thrift:
使用gRPC的公司或项目:
Google
Mochi中国
阿里OTS
腾讯部分部门
Tensorflow项目中使用了grpc
CoreOS — Production API for etcd v3 is entirely gRPC. etcd v3的接口全部使用grpc
Square — replacement for all of their internal RPC. one of the very first adopters and contributors to gRPC.
ngrok — all 20+ internal services communicate via gRPC 一个内网转发产品
Netflix
Yik Yak
VSCO
Cockroach
使用Thrift的公司或项目:
Facebook
雪球
饿了么
今日头条
evernote
友盟
小米
美团
Quora
Twitter
Pinterest
Foursquare
Maxeler Technologies
gRPC优缺点:
优点:
protobuf二进制消息,性能好/效率高(空间和时间效率都很不错)
proto文件生成目标代码,简单易用
序列化反序列化直接对应程序中的数据类,不需要解析后在进行映射(XML,JSON都是这种方式)
支持向前兼容(新加字段采用默认值)和向后兼容(忽略新加字段),简化升级
支持多种语言(可以把proto文件看做IDL文件)
Netty等一些框架集成
缺点:
1)GRPC尚未提供连接池,需要自行实现
2)尚未提供“服务发现”、“负载均衡”机制
3)因为基于HTTP2,绝大部多数HTTP Server、Nginx都尚不支持,即Nginx不能将GRPC请求作为HTTP请求来负载均衡,而是作为普通的TCP请求。(nginx1.9版本已支持)
4) Protobuf二进制可读性差(貌似提供了Text_Fromat功能)
默认不具备动态特性(可以通过动态定义生成消息类型或者动态编译支持)
grpc坑:
来自https://news.ycombinator.com/item?id=12345223的网友:
http2只允许单个链接传输10亿流数据。原因在于:
htt2使用31位整形标示流,服务端使用奇数,客户端使用偶数,所以总共10亿可用。
-
HTTP/2.0 uses an unsigned 31-bit integer to identity individual streams over a connection.
-
Server-initiated streams must
use even identifiers.
-
Client-initiated streams must
use odd identifiers.
- 1
- 2
- 3
解决思路:超过一定数量的流,需要重启链接。
gRPC通信方式
gRPC有四种通信方式:
1、 Simple RPC
简单rpc
这就是一般的rpc调用,一个请求对象对应一个返回对象
proto语法:
rpc simpleHello(Person) returns (Result) {}
- 1
2、 Server-side streaming RPC
服务端流式rpc
一个请求对象,服务端可以传回多个结果对象
proto语法
rpc serverStreamHello(Person) returns (stream Result) {}
- 1
3、 Client-side streaming RPC
客户端流式rpc
客户端传入多个请求对象,服务端返回一个响应结果
proto语法
rpc clientStreamHello(stream Person) returns (Result) {}
- 1
4、 Bidirectional streaming RPC
双向流式rpc
结合客户端流式rpc和服务端流式rpc,可以传入多个对象,返回多个响应对象
proto语法
rpc biStreamHello(stream Person) returns (stream Result) {}
- 1
服务定义及ProtoBuf
gRPC使用ProtoBuf定义服务, 我们可以一次性的在一个 .proto 文件中定义服务并使用任何支持它的语言去实现客户端和服务器,反过来,它们可以在各种环境中,从云服务器到你自己的平板电脑—— gRPC 帮你解决了不同语言及环境间通信的复杂性。使用 protocol buffers 还能获得其他好处,包括高效的序列号,简单的 IDL 以及容易进行接口更新。
protoc编译工具
protoc工具可在https://github.com/google/protobuf/releases 下载到源码。
linux下安装
protobuf语法
1、syntax = “proto3”;
文件的第一行指定了你使用的是proto3的语法:如果你不指定,protocol buffer 编译器就会认为你使用的是proto2的语法。这个语句必须出现在.proto文件的非空非注释的第一行。
2、message SearchRequest {……}
message 定义实体,c/c++/go中的结构体,php中类
3、基本数据类型
4、注释符号: 双斜线,如://xxxxxxxxxxxxxxxxxxx
5、字段唯一数字标识(用于在二进制格式中识别各个字段,上线后不宜再变动):Tags
1到15使用一个字节来编码,包括标识数字和字段类型(你可以在Protocol Buffer 编码中查看更多详细);16到2047占用两个字节。因此定义proto文件时应该保留1到15,用作出现最频繁的消息类型的标识。记得为将来会继续增加并可能频繁出现的元素留一点儿标识区间,也就是说,不要一下子把1—15全部用完,为将来留一点儿。
标识数字的合法范围:最小是1,最大是 229 - 1,或者536,870,911。
另外,不能使用19000 到 19999之间的数字(FieldDescriptor::kFirstReservedNumber through FieldDescriptor::kLastReservedNumber),因为它们被Protocol Buffers保留使用
6、字段修饰符:
required:值不可为空
optional:可选字段
singular:符合语法规则的消息包含零个或者一个这样的字段(最多一个)
repeated:一个字段在合法的消息中可以重复出现一定次数(包括零次)。重复出现的值的次序将被保留。在proto3中,重复出现的值类型字段默认采用压缩编码。你可以在这里找到更多关于压缩编码的东西: Protocol Buffer Encoding。
默认值: optional PhoneType type = 2 [default = HOME];
proto3中,省略required,optional,singular,由protoc自动选择。
7、代理类生成
1)、C++, 每一个.proto 文件可以生成一个 .h 文件和一个 .cc 文件
2)、Java, 每一个.proto文件可以生成一个 .java 文件
3)、Python, 每一个.proto文件生成一个模块,其中为每一个消息类型生成一个静态的描述器,在运行时,和一个metaclass一起使用来创建必要的Python数据访问类
4)、Go, 每一个.proto生成一个 .pb.go 文件
5)、Ruby, 每一个.proto生成一个 .rb 文件
6)、Objective-C, 每一个.proto 文件可以生成一个 pbobjc.h 和一个pbobjc.m 文件
7)、C#, 每一个.proto文件可以生成一个.cs文件.
8)、php, 每一个message消息体生成一个.php类文件,并在GPBMetadata目录生成一个对应包名的.php类文件,用于保存.proto的二进制元数据。
8、字段默认值
- strings, 默认值是空字符串(empty string)
- bytes, 默认值是空bytes(empty bytes)
- bools, 默认值是false
- numeric, 默认值是0
- enums, 默认值是第一个枚举值(value必须为0)
- message fields, the field is not set. Its exact value is langauge-dependent. See the generated code guide for details.
- repeated fields,默认值为empty,通常是一个空list
9、枚举
-
// 枚举类型,必须从0开始,序号可跨越。同一包下不能重名,所以加前缀来区别
-
enum WshExportInstStatus {
-
INST_INITED =
0;
-
INST_RUNNING =
1;
-
INST_FINISH =
2;
-
INST_FAILED =
3;
-
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
10、Maps字段类型
map<key_type, value_type> map_field = N;
- 1
其中key_type可以是任意Integer或者string类型(所以,除了floating和bytes的任意标量类型都是可以的)value_type可以是任意类型。
例如,如果你希望创建一个project的映射,每个Projecct使用一个string作为key,你可以像下面这样定义:
map<string, Project> projects = 3;
- 1
- Map的字段可以是repeated。
- 序列化后的顺序和map迭代器的顺序是不确定的,所以你不要期望以固定顺序处理Map
- 当为.proto文件产生生成文本格式的时候,map会按照key 的顺序排序,数值化的key会按照数值排序。
- 从序列化中解析或者融合时,如果有重复的key则后一个key不会被使用,当从文本格式中解析map时,如果存在重复的key。
11、默认值
字符串类型默认为空字符串
字节类型默认为空字节
布尔类型默认false
数值类型默认为0值
enums类型默认为第一个定义的枚举值,必须是0
12、服务
服务使用service{}包起来,每个方法使用rpc起一行申明,一个方法包含一个请求消息体和一个返回消息体
-
service HelloService {
-
rpc SayHello (HelloRequest) returns (HelloResponse);
-
}
-
message HelloRequest {
-
string greeting =
1;
-
}
-
-
message HelloResponse {
-
string reply =
1;
-
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
更多protobuf参考(google)
更多protobuf参考(csdn)
golang中使用gRPC
前期准备
-
go
get -u
"google.golang.org/grpc"
-
go
get -u
"google.golang.org/grpc/reflection"
- 1
- 2
例如我定义的文件exporttask.proto:
-
// 微生活导出服务
-
// 导出功能接口
-
/*
-
1、 创建任务模板
-
2、 查询、列出任务模板
-
3、 删除任务模板
-
4、 添加导出任务实例
-
5、 查询任务状态
-
*/
-
syntax =
"proto3";
-
-
// java 语法特别选项
-
option java_multiple_files =
true;
-
option java_package =
"io.grpc.welife.WshExportTask";
-
option java_outer_classname =
"WshExportTask";
-
// 包名 golang包名,php中namespase,
-
package exporttask;
-
-
// 导出任务服务定义
-
service ExportTask {
-
// 创建任务模板
-
rpc CreateTpl(WshExportTaskCreateTplReq) returns (WshExportTaskCreateTplRes) {}
-
// 查询任务模板
-
rpc ListTpl(WshExportTaskListTplReq) returns (WshExportTaskListTplRes) {}
-
}
-
-
// 枚举类型,必须从0开始,序号可跨越。同一包下不能重名,所以加前缀来区别
-
enum WshExportTplStatus {
-
TPL_INITED =
0;
-
TPL_NORMAL =
1;
-
TPL_DELETED =
9;
-
}
-
-
enum WshExportFormat {
-
FMT_DEFAULT =
0;
-
FMT_CSV =
1;
-
FMT_XLS =
2;
-
}
-
-
message WshExportTpl {
-
string etplName =
1;
-
string etplTag =
2;
-
WshExportFormat etplOutputFormat =
3;
-
string etplOutputColumns =
4;
-
string etplExpr =
5;
-
int32 etplId =
6;
-
int32 etplExecTimes =
7;
-
int32 etplExecOkTimes =
8;
-
int32 etplStatus =
9;
-
string etplCreated =
10;
-
string etplUpdated =
11;
-
string etplDeleted =
12;
-
int32 operatorId =
13;
-
}
-
-
message WshExportTaskCreateTplReq {
-
string etplName =
1;
-
string etplTag =
2;
-
string etplExpr =
3;
-
string etplOutputColumns =
4;
-
WshExportFormat etplOutputFormat =
5;
-
int32 operatorId =
6;
-
}
-
-
message WshExportTaskCreateTplRes {
-
string errCode =
1;
-
string errMsg =
2;
-
WshExportTpl data =
3;
-
}
-
-
message WshExportTaskListTplReq {
-
int32 etplId =
1;
-
string etplName =
2;
-
string etplTag =
3;
-
}
-
-
// repeated 表示数组
-
message WshExportTaskListTplRes {
-
string errCode =
1;
-
string errMsg =
2;
-
repeated WshExportTpl data =
3;
-
}
-
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
使用protoc命令生成golang对应的rpc代码:
-
#格式 protoc --go_out=plugins=grpc:{go代码输出路径} {proto文件}
-
protoc --go_out=plugins=grpc:./ ./exporttask.proto
- 1
- 2
生成对应当exporttask.pb.go
-
// Code generated by protoc-gen-go. DO NOT EDIT.
-
// source: exporttask.proto
-
-
/*
-
Package exporttask is a generated protocol buffer package.
-
-
包名 golang包名,php中namespase,
-
-
It is generated from these files:
-
exporttask.proto
-
-
It has these top-level messages:
-
WshExportTpl
-
WshExportTaskCreateTplReq
-
WshExportTaskCreateTplRes
-
WshExportTaskListTplReq
-
WshExportTaskListTplRes
-
*/
-
package exporttask
-
-
import proto
"github.com/golang/protobuf/proto"
-
import fmt
"fmt"
-
import math
"math"
-
-
import (
-
context
"golang.org/x/net/context"
-
grpc
"google.golang.org/grpc"
-
)
-
-
// Reference imports to suppress errors if they are not otherwise used.
-
var _ = proto.Marshal
-
var _ = fmt.Errorf
-
var _ = math.Inf
-
-
// This is a compile-time assertion to ensure that this generated file
-
// is compatible with the proto package it is being compiled against.
-
// A compilation error at this line likely means your copy of the
-
// proto package needs to be updated.
-
const _ = proto.ProtoPackageIsVersion2
// please upgrade the proto package
-
-
// 枚举类型,必须从0开始,序号可跨越。同一包下不能重名,所以加前缀来区别
-
type WshExportTplStatus
int32
-
-
const (
-
WshExportTplStatus_TPL_INITED WshExportTplStatus =
0
-
WshExportTplStatus_TPL_NORMAL WshExportTplStatus =
1
-
WshExportTplStatus_TPL_DELETED WshExportTplStatus =
9
-
)
-
-
var WshExportTplStatus_name =
map[
int32]
string{
-
0:
"TPL_INITED",
-
1:
"TPL_NORMAL",
-
9:
"TPL_DELETED",
-
}
-
var WshExportTplStatus_value =
map[
string]
int32{
-
"TPL_INITED":
0,
-
"TPL_NORMAL":
1,
-
"TPL_DELETED":
9,
-
}
-
-
func (x WshExportTplStatus) String() string {
-
return proto.EnumName(WshExportTplStatus_name,
int32(x))
-
}
-
func (WshExportTplStatus) EnumDescriptor() ([]byte, []int) {
return fileDescriptor0, []
int{
0} }
-
-
type WshExportFormat
int32
-
-
const (
-
WshExportFormat_FMT_DEFAULT WshExportFormat =
0
-
WshExportFormat_FMT_CSV WshExportFormat =
1
-
WshExportFormat_FMT_XLS WshExportFormat =
2
-
)
-
-
var WshExportFormat_name =
map[
int32]
string{
-
0:
"FMT_DEFAULT",
-
1:
"FMT_CSV",
-
2:
"FMT_XLS",
-
}
-
var WshExportFormat_value =
map[
string]
int32{
-
"FMT_DEFAULT":
0,
-
"FMT_CSV":
1,
-
"FMT_XLS":
2,
-
}
-
-
func (x WshExportFormat) String() string {
-
return proto.EnumName(WshExportFormat_name,
int32(x))
-
}
-
func (WshExportFormat) EnumDescriptor() ([]byte, []int) {
return fileDescriptor0, []
int{
1} }
-
-
type WshExportTpl
struct {
-
EtplName
string
`protobuf:"bytes,1,opt,name=etplName" json:"etplName,omitempty"`
-
EtplTag
string
`protobuf:"bytes,2,opt,name=etplTag" json:"etplTag,omitempty"`
-
EtplOutputFormat WshExportFormat
`protobuf:"varint,3,opt,name=etplOutputFormat,enum=exporttask.WshExportFormat" json:"etplOutputFormat,omitempty"`
-
EtplOutputColumns
string
`protobuf:"bytes,4,opt,name=etplOutputColumns" json:"etplOutputColumns,omitempty"`
-
EtplExpr
string
`protobuf:"bytes,5,opt,name=etplExpr" json:"etplExpr,omitempty"`
-
EtplId
int32
`protobuf:"varint,6,opt,name=etplId" json:"etplId,omitempty"`
-
EtplExecTimes
int32
`protobuf:"varint,7,opt,name=etplExecTimes" json:"etplExecTimes,omitempty"`
-
EtplExecOkTimes
int32
`protobuf:"varint,8,opt,name=etplExecOkTimes" json:"etplExecOkTimes,omitempty"`
-
EtplStatus
int32
`protobuf:"varint,9,opt,name=etplStatus" json:"etplStatus,omitempty"`
-
EtplCreated
string
`protobuf:"bytes,10,opt,name=etplCreated" json:"etplCreated,omitempty"`
-
EtplUpdated
string
`protobuf:"bytes,11,opt,name=etplUpdated" json:"etplUpdated,omitempty"`
-
EtplDeleted
string
`protobuf:"bytes,12,opt,name=etplDeleted" json:"etplDeleted,omitempty"`
-
OperatorId
int32
`protobuf:"varint,13,opt,name=operatorId" json:"operatorId,omitempty"`
-
}
-
-
func (m *WshExportTpl) Reset() { *m = WshExportTpl{} }
-
func (m *WshExportTpl) String() string {
return proto.CompactTextString(m) }
-
func (*WshExportTpl) ProtoMessage() {}
-
func (*WshExportTpl) Descriptor() ([]byte, []int) {
return fileDescriptor0, []
int{
0} }
-
-
func (m *WshExportTpl) GetEtplName() string {
-
if m !=
nil {
-
return m.EtplName
-
}
-
return
""
-
}
-
-
func (m *WshExportTpl) GetEtplTag() string {
-
if m !=
nil {
-
return m.EtplTag
-
}
-
return
""
-
}
-
-
func (m *WshExportTpl) GetEtplOutputFormat() WshExportFormat {
-
if m !=
nil {
-
return m.EtplOutputFormat
-
}
-
return WshExportFormat_FMT_DEFAULT
-
}
-
-
func (m *WshExportTpl) GetEtplOutputColumns() string {
-
if m !=
nil {
-
return m.EtplOutputColumns
-
}
-
return
""
-
}
-
-
func (m *WshExportTpl) GetEtplExpr() string {
-
if m !=
nil {
-
return m.EtplExpr
-
}
-
return
""
-
}
-
-
func (m *WshExportTpl) GetEtplId() int32 {
-
if m !=
nil {
-
return m.EtplId
-
}
-
return
0
-
}
-
-
func (m *WshExportTpl) GetEtplExecTimes() int32 {
-
if m !=
nil {
-
return m.EtplExecTimes
-
}
-
return
0
-
}
-
-
func (m *WshExportTpl) GetEtplExecOkTimes() int32 {
-
if m !=
nil {
-
return m.EtplExecOkTimes
-
}
-
return
0
-
}
-
-
func (m *WshExportTpl) GetEtplStatus() int32 {
-
if m !=
nil {
-
return m.EtplStatus
-
}
-
return
0
-
}
-
-
func (m *WshExportTpl) GetEtplCreated() string {
-
if m !=
nil {
-
return m.EtplCreated
-
}
-
return
""
-
}
-
-
func (m *WshExportTpl) GetEtplUpdated() string {
-
if m !=
nil {
-
return m.EtplUpdated
-
}
-
return
""
-
}
-
-
func (m *WshExportTpl) GetEtplDeleted() string {
-
if m !=
nil {
-
return m.EtplDeleted
-
}
-
return
""
-
}
-
-
func (m *WshExportTpl) GetOperatorId() int32 {
-
if m !=
nil {
-
return m.OperatorId
-
}
-
return
0
-
}
-
-
type WshExportTaskCreateTplReq
struct {
-
EtplName
string
`protobuf:"bytes,1,opt,name=etplName" json:"etplName,omitempty"`
-
EtplTag
string
`protobuf:"bytes,2,opt,name=etplTag" json:"etplTag,omitempty"`
-
EtplExpr
string
`protobuf:"bytes,3,opt,name=etplExpr" json:"etplExpr,omitempty"`
-
EtplOutputColumns
string
`protobuf:"bytes,4,opt,name=etplOutputColumns" json:"etplOutputColumns,omitempty"`
-
EtplOutputFormat WshExportFormat
`protobuf:"varint,5,opt,name=etplOutputFormat,enum=exporttask.WshExportFormat" json:"etplOutputFormat,omitempty"`
-
OperatorId
int32
`protobuf:"varint,6,opt,name=operatorId" json:"operatorId,omitempty"`
-
}
-
-
func (m *WshExportTaskCreateTplReq) Reset() { *m = WshExportTaskCreateTplReq{} }
-
func (m *WshExportTaskCreateTplReq) String() string {
return proto.CompactTextString(m) }
-
func (*WshExportTaskCreateTplReq) ProtoMessage() {}
-
func (*WshExportTaskCreateTplReq) Descriptor() ([]byte, []int) {
return fileDescriptor0, []
int{
1} }
-
-
func (m *WshExportTaskCreateTplReq) GetEtplName() string {
-
if m !=
nil {
-
return m.EtplName
-
}
-
return
""
-
}
-
-
func (m *WshExportTaskCreateTplReq) GetEtplTag() string {
-
if m !=
nil {
-
return m.EtplTag
-
}
-
return
""
-
}
-
-
func (m *WshExportTaskCreateTplReq) GetEtplExpr() string {
-
if m !=
nil {
-
return m.EtplExpr
-
}
-
return
""
-
}
-
-
func (m *WshExportTaskCreateTplReq) GetEtplOutputColumns() string {
-
if m !=
nil {
-
return m.EtplOutputColumns
-
}
-
return
""
-
}
-
-
func (m *WshExportTaskCreateTplReq) GetEtplOutputFormat() WshExportFormat {
-
if m !=
nil {
-
return m.EtplOutputFormat
-
}
-
return WshExportFormat_FMT_DEFAULT
-
}
-
-
func (m *WshExportTaskCreateTplReq) GetOperatorId() int32 {
-
if m !=
nil {
-
return m.OperatorId
-
}
-
return
0
-
}
-
-
type WshExportTaskCreateTplRes
struct {
-
ErrCode
string
`protobuf:"bytes,1,opt,name=errCode" json:"errCode,omitempty"`
-
ErrMsg
string
`protobuf:"bytes,2,opt,name=errMsg" json:"errMsg,omitempty"`
-
Data *WshExportTpl
`protobuf:"bytes,3,opt,name=data" json:"data,omitempty"`
-
}
-
-
func (m *WshExportTaskCreateTplRes) Reset() { *m = WshExportTaskCreateTplRes{} }
-
func (m *WshExportTaskCreateTplRes) String() string {
return proto.CompactTextString(m) }
-
func (*WshExportTaskCreateTplRes) ProtoMessage() {}
-
func (*WshExportTaskCreateTplRes) Descriptor() ([]byte, []int) {
return fileDescriptor0, []
int{
2} }
-
-
func (m *WshExportTaskCreateTplRes) GetErrCode() string {
-
if m !=
nil {
-
return m.ErrCode
-
}
-
return
""
-
}
-
-
func (m *WshExportTaskCreateTplRes) GetErrMsg() string {
-
if m !=
nil {
-
return m.ErrMsg
-
}
-
return
""
-
}
-
-
func (m *WshExportTaskCreateTplRes) GetData() *WshExportTpl {
-
if m !=
nil {
-
return m.Data
-
}
-
return
nil
-
}
-
-
type WshExportTaskListTplReq
struct {
-
EtplId
int32
`protobuf:"varint,1,opt,name=etplId" json:"etplId,omitempty"`
-
EtplName
string
`protobuf:"bytes,2,opt,name=etplName" json:"etplName,omitempty"`
-
EtplTag
string
`protobuf:"bytes,3,opt,name=etplTag" json:"etplTag,omitempty"`
-
}
-
-
func (m *WshExportTaskListTplReq) Reset() { *m = WshExportTaskListTplReq{} }
-
func (m *WshExportTaskListTplReq) String() string {
return proto.CompactTextString(m) }
-
func (*WshExportTaskListTplReq) ProtoMessage() {}
-
func (*WshExportTaskListTplReq) Descriptor() ([]byte, []int) {
return fileDescriptor0, []
int{
3} }
-
-
func (m *WshExportTaskListTplReq) GetEtplId() int32 {
-
if m !=
nil {
-
return m.EtplId
-
}
-
return
0
-
}
-
-
func (m *WshExportTaskListTplReq) GetEtplName() string {
-
if m !=
nil {
-
return m.EtplName
-
}
-
return
""
-
}
-
-
func (m *WshExportTaskListTplReq) GetEtplTag() string {
-
if m !=
nil {
-
return m.EtplTag
-
}
-
return
""
-
}
-
-
// repeated 表示数组
-
type WshExportTaskListTplRes
struct {
-
ErrCode
string
`protobuf:"bytes,1,opt,name=errCode" json:"errCode,omitempty"`
-
ErrMsg
string
`protobuf:"bytes,2,opt,name=errMsg" json:"errMsg,omitempty"`
-
Data []*WshExportTpl
`protobuf:"bytes,3,rep,name=data" json:"data,omitempty"`
-
}
-
-
func (m *WshExportTaskListTplRes) Reset() { *m = WshExportTaskListTplRes{} }
-
func (m *WshExportTaskListTplRes) String() string {
return proto.CompactTextString(m) }
-
func (*WshExportTaskListTplRes) ProtoMessage() {}
-
func (*WshExportTaskListTplRes) Descriptor() ([]byte, []int) {
return fileDescriptor0, []
int{
4} }
-
-
func (m *WshExportTaskListTplRes) GetErrCode() string {
-
if m !=
nil {
-
return m.ErrCode
-
}
-
return
""
-
}
-
-
func (m *WshExportTaskListTplRes) GetErrMsg() string {
-
if m !=
nil {
-
return m.ErrMsg
-
}
-
return
""
-
}
-
-
func (m *WshExportTaskListTplRes) GetData() []*WshExportTpl {
-
if m !=
nil {
-
return m.Data
-
}
-
return
nil
-
}
-
-
func init() {
-
proto.RegisterType((*WshExportTpl)(
nil),
"exporttask.WshExportTpl")
-
proto.RegisterType((*WshExportTaskCreateTplReq)(
nil),
"exporttask.WshExportTaskCreateTplReq")
-
proto.RegisterType((*WshExportTaskCreateTplRes)(
nil),
"exporttask.WshExportTaskCreateTplRes")
-
proto.RegisterType((*WshExportTaskListTplReq)(
nil),
"exporttask.WshExportTaskListTplReq")
-
proto.RegisterType((*WshExportTaskListTplRes)(
nil),
"exporttask.WshExportTaskListTplRes")
-
proto.RegisterEnum(
"exporttask.WshExportTplStatus", WshExportTplStatus_name, WshExportTplStatus_value)
-
proto.RegisterEnum(
"exporttask.WshExportFormat", WshExportFormat_name, WshExportFormat_value)
-
}
-
-
// Reference imports to suppress errors if they are not otherwise used.
-
var _ context.Context
-
var _ grpc.ClientConn
-
-
// This is a compile-time assertion to ensure that this generated file
-
// is compatible with the grpc package it is being compiled against.
-
const _ = grpc.SupportPackageIsVersion4
-
-
// Client API for ExportTask service
-
-
type ExportTaskClient
interface {
-
// 创建任务模板
-
CreateTpl(ctx context.Context, in *WshExportTaskCreateTplReq, opts ...grpc.CallOption) (*WshExportTaskCreateTplRes, error)
-
// 查询任务模板
-
ListTpl(ctx context.Context, in *WshExportTaskListTplReq, opts ...grpc.CallOption) (*WshExportTaskListTplRes, error)
-
}
-
-
type exportTaskClient
struct {
-
cc *grpc.ClientConn
-
}
-
-
func NewExportTaskClient(cc *grpc.ClientConn) ExportTaskClient {
-
return &exportTaskClient{cc}
-
}
-
-
func (c *exportTaskClient) CreateTpl(ctx context.Context, in *WshExportTaskCreateTplReq, opts ...grpc.CallOption) (*WshExportTaskCreateTplRes, error) {
-
out :=
new(WshExportTaskCreateTplRes)
-
err := grpc.Invoke(ctx,
"/exporttask.ExportTask/CreateTpl", in, out, c.cc, opts...)
-
if err !=
nil {
-
return
nil, err
-
}
-
return out,
nil
-
}
-
-
func (c *exportTaskClient) ListTpl(ctx context.Context, in *WshExportTaskListTplReq, opts ...grpc.CallOption) (*WshExportTaskListTplRes, error) {
-
out :=
new(WshExportTaskListTplRes)
-
err := grpc.Invoke(ctx,
"/exporttask.ExportTask/ListTpl", in, out, c.cc, opts...)
-
if err !=
nil {
-
return
nil, err
-
}
-
return out,
nil
-
}
-
-
// Server API for ExportTask service
-
-
type ExportTaskServer
interface {
-
// 创建任务模板
-
CreateTpl(context.Context, *WshExportTaskCreateTplReq) (*WshExportTaskCreateTplRes, error)
-
// 查询任务模板
-
ListTpl(context.Context, *WshExportTaskListTplReq) (*WshExportTaskListTplRes, error)
-
}
-
-
func RegisterExportTaskServer(s *grpc.Server, srv ExportTaskServer) {
-
s.RegisterService(&_ExportTask_serviceDesc, srv)
-
}
-
-
func _ExportTask_CreateTpl_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
-
in :=
new(WshExportTaskCreateTplReq)
-
if err := dec(in); err !=
nil {
-
return
nil, err
-
}
-
if interceptor ==
nil {
-
return srv.(ExportTaskServer).CreateTpl(ctx, in)
-
}
-
info := &grpc.UnaryServerInfo{
-
Server: srv,
-
FullMethod:
"/exporttask.ExportTask/CreateTpl",
-
}
-
handler :=
func(ctx context.Context, req interface{}) (interface{}, error) {
-
return srv.(ExportTaskServer).CreateTpl(ctx, req.(*WshExportTaskCreateTplReq))
-
}
-
return interceptor(ctx, in, info, handler)
-
}
-
-
func _ExportTask_ListTpl_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
-
in :=
new(WshExportTaskListTplReq)
-
if err := dec(in); err !=
nil {
-
return
nil, err
-
}
-
if interceptor ==
nil {
-
return srv.(ExportTaskServer).ListTpl(ctx, in)
-
}
-
info := &grpc.UnaryServerInfo{
-
Server: srv,
-
FullMethod:
"/exporttask.ExportTask/ListTpl",
-
}
-
handler :=
func(ctx context.Context, req interface{}) (interface{}, error) {
-
return srv.(ExportTaskServer).ListTpl(ctx, req.(*WshExportTaskListTplReq))
-
}
-
return interceptor(ctx, in, info, handler)
-
}
-
-
var _ExportTask_serviceDesc = grpc.ServiceDesc{
-
ServiceName:
"exporttask.ExportTask",
-
HandlerType: (*ExportTaskServer)(
nil),
-
Methods: []grpc.MethodDesc{
-
{
-
MethodName:
"CreateTpl",
-
Handler: _ExportTask_CreateTpl_Handler,
-
},
-
{
-
MethodName:
"ListTpl",
-
Handler: _ExportTask_ListTpl_Handler,
-
},
-
},
-
Streams: []grpc.StreamDesc{},
-
Metadata:
"exporttask.proto",
-
}
-
-
func init() { proto.RegisterFile(
"exporttask.proto", fileDescriptor0) }
-
-
var fileDescriptor0 = []
byte{
-
// 550 bytes of a gzipped FileDescriptor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0x60,
0x9b,
-
0xec,
0x89,
0xef,
0x05,
0x00,
0x00,
-
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 345
- 346
- 347
- 348
- 349
- 350
- 351
- 352
- 353
- 354
- 355
- 356
- 357
- 358
- 359
- 360
- 361
- 362
- 363
- 364
- 365
- 366
- 367
- 368
- 369
- 370
- 371
- 372
- 373
- 374
- 375
- 376
- 377
- 378
- 379
- 380
- 381
- 382
- 383
- 384
- 385
- 386
- 387
- 388
- 389
- 390
- 391
- 392
- 393
- 394
- 395
- 396
- 397
- 398
- 399
- 400
- 401
- 402
- 403
- 404
- 405
- 406
- 407
- 408
- 409
- 410
- 411
- 412
- 413
- 414
- 415
- 416
- 417
- 418
- 419
- 420
- 421
- 422
- 423
- 424
- 425
- 426
- 427
- 428
- 429
- 430
- 431
- 432
- 433
- 434
- 435
- 436
- 437
- 438
- 439
- 440
- 441
- 442
- 443
- 444
- 445
- 446
- 447
- 448
- 449
- 450
- 451
- 452
- 453
- 454
- 455
- 456
- 457
- 458
- 459
- 460
- 461
- 462
- 463
- 464
- 465
- 466
- 467
- 468
- 469
- 470
- 471
- 472
- 473
- 474
- 475
- 476
- 477
- 478
- 479
- 480
- 481
- 482
- 483
- 484
- 485
- 486
- 487
- 488
- 489
- 490
- 491
- 492
- 493
- 494
- 495
- 496
- 497
- 498
- 499
- 500
- 501
- 502
- 503
- 504
- 505
- 506
- 507
- 508
- 509
- 510
- 511
- 512
- 513
- 514
服务端实现proto中的接口:
-
package main
-
-
import (
-
"log"
-
//"net"
-
-
svcExport
"../../common/exporttask"
// 包含上面的pb生成的go包
-
"./model"
-
_
"github.com/go-sql-driver/mysql"
-
"golang.org/x/net/context"
-
//"google.golang.org/grpc"
-
//"google.golang.org/grpc/reflection"
-
)
-
-
// server 这个对象来实现 exporttask 包中的pb定义的rpc服务
-
// 实现的方式是将服务转化成本地的数据库操作
-
type server
struct{}
-
-
func (s *server) CreateTpl(ctx context.Context, in *svcExport.WshExportTaskCreateTplReq) (res *svcExport.WshExportTaskCreateTplRes, err error) {
-
res =
new(svcExport.WshExportTaskCreateTplRes)
-
res.Data =
new(svcExport.WshExportTpl)
-
-
var etplId
int32 =
0
-
-
etplId, err = model.CreateTpl(in.EtplName, in.EtplTag, in.EtplExpr, in.EtplOutputColumns,
int32(in.EtplOutputFormat), in.OperatorId)
-
//res.Data, err = model.GetTpl(etplId)
-
res.Data.EtplId = etplId
-
return res, err
-
}
-
-
func (s *server) ListTpl(ctx context.Context, in *svcExport.WshExportTaskListTplReq) (*svcExport.WshExportTaskListTplRes, error) {
-
res :=
new(svcExport.WshExportTaskListTplRes)
-
entList, err := model.ListTpl(in.EtplId, in.EtplName, in.EtplTag)
-
-
if err !=
nil {
-
res.ErrMsg = err.Error()
-
res.ErrCode =
"2"
-
}
-
-
for _, ent :=
range entList {
-
t :=
new(svcExport.WshExportTpl)
-
ent.CopyToPb(t)
-
res.Data =
append(res.Data, t)
-
}
-
-
return res, err
-
}
-
-
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
服务端main启动服务main.go
-
/**
-
* exporttask server main
-
* $ go build exporttask.go
-
*/
-
package main
-
-
import (
-
"log"
-
"net"
-
-
svcExport
"../../common/exporttask"
-
//"./model"
-
_
"github.com/go-sql-driver/mysql"
-
//"golang.org/x/net/context"
-
"google.golang.org/grpc"
-
"google.golang.org/grpc/reflection"
-
)
-
-
const (
-
port =
":50051"
-
)
-
-
func main() {
-
lis, err := net.Listen(
"tcp", port)
-
if err !=
nil {
-
log.Fatalf(
"failed to listen: %v", err)
-
}
-
// 生成一个rpc服务器
-
s := grpc.NewServer()
-
// 使用pb包调用注册已实现的rpc接口类server
-
svcExport.RegisterExportTaskServer(s, &server{})
-
// Register reflection service on gRPC server.
-
reflection.Register(s)
-
if err := s.Serve(lis); err !=
nil {
-
log.Fatalf(
"failed to serve: %v", err)
-
}
-
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
Golang gRPC客户端
客户端的代码相对比较简单
-
package main
-
-
import (
-
"flag"
-
"log"
-
"os"
-
-
svcExport
"../../common/exporttask"
-
"golang.org/x/net/context"
-
"google.golang.org/grpc"
-
)
-
-
const (
-
address =
"127.0.0.1:50052"
-
defaultName =
"world"
-
)
-
-
func main() {
-
-
// 发起链接
-
conn, err := grpc.Dial(address, grpc.WithInsecure())
-
if err !=
nil {
-
log.Fatalf(
"did not connect: %v", err)
-
}
-
defer conn.Close()
-
-
// 创建pb包的客户端
-
c := svcExport.NewExportTaskClient(conn)
-
-
name := defaultName
-
if
len(os.Args) >
1 {
-
name = os.Args[
1]
-
}
-
-
// 发起请求
-
var r2 *svcExport.WshExportTaskCreateTplRes
-
req := svcExport.WshExportTaskCreateTplReq{EtplName: name, EtplTag:
"mall", EtplExpr:
"select EtplName from welife_export_tpl", EtplOutputFormat: svcExport.WshExportFormat_FMT_CSV, EtplOutputColumns:
""}
-
r2, err = c.CreateTpl(context.Background(), &req)
-
// 打印结果
-
log.Println(
"create tpl: r=", r2, err)
-
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
php中使用gRPC
php需要安装grpc扩展。
使用protoc命令生成对应的php代码:
protoc --php_out=plugins=grpc:./ exporttask.proto
- 1
- 2
生成代码包括:
-
Exporttask/
-
|-WshExportFormat.php
-
|-WshExportTaskCreateTplReq.php
-
|-WshExportTaskCreateTplRes.php
-
|-WshExportTaskListTplReq.php
-
|-WshExportTaskListTplRes.php
-
|-WshExportTpl.php
-
\-WshExportTplStatus.php
-
GPBMetadata/
-
\-Exporttask.php
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
每一个message对应生成一个类,在Exporttask命名空间下。
这里就不都贴出来了,只贴一个WshExportTpl.php:
-
<?php
-
# Generated by the protocol buffer compiler. DO NOT EDIT!
-
# source: exporttask.proto
-
-
namespace
Exporttask;
-
-
use
Google\
Protobuf\
Internal\
GPBType;
-
use
Google\
Protobuf\
Internal\
RepeatedField;
-
use
Google\
Protobuf\
Internal\
GPBUtil;
-
-
/**
-
* Protobuf type <code>exporttask.WshExportTpl</code>
-
*/
-
class WshExportTpl extends \Google\Protobuf\Internal\Message
-
{
-
/**
-
* <code>string etplName = 1;</code>
-
*/
-
private $etplName =
'';
-
/**
-
* <code>string etplTag = 2;</code>
-
*/
-
private $etplTag =
'';
-
/**
-
* <code>.exporttask.WshExportFormat etplOutputFormat = 3;</code>
-
*/
-
private $etplOutputFormat =
0;
-
/**
-
* <code>string etplOutputColumns = 4;</code>
-
*/
-
private $etplOutputColumns =
'';
-
/**
-
* <code>string etplExpr = 5;</code>
-
*/
-
private $etplExpr =
'';
-
/**
-
* <code>int32 etplId = 6;</code>
-
*/
-
private $etplId =
0;
-
/**
-
* <code>int32 etplExecTimes = 7;</code>
-
*/
-
private $etplExecTimes =
0;
-
/**
-
* <code>int32 etplExecOkTimes = 8;</code>
-
*/
-
private $etplExecOkTimes =
0;
-
/**
-
* <code>int32 etplStatus = 9;</code>
-
*/
-
private $etplStatus =
0;
-
/**
-
* <code>string etplCreated = 10;</code>
-
*/
-
private $etplCreated =
'';
-
/**
-
* <code>string etplUpdated = 11;</code>
-
*/
-
private $etplUpdated =
'';