MacOS Java+golang build protoc gRPC 代码生成

简介: MACOS Java+golang GRPC 代码生成 下载protobuf git clone https://github.com/protocolbuffers/protobuf.git git checkout 3.

MacOS Java+golang gRPC 代码生成

编译protobuf/protoc 工具

git clone https://github.com/protocolbuffers/protobuf.git
git checkout 3.3.x

mac 环境安装autoconf automake

brew install autoconf
brew install automake

build protobuf

cd protobuf
./autogen.sh
./configure
make
sudo make install

编译grpc-java

下载grpc-java

git clone https://github.com/grpc/grpc-java.git
git checkout git checkout v1.4.x

编译grpc-java

cd grpc-java
./gradlew build

生成目标文件compiler/build/exe/java_plugin/protoc-gen-grpc-java

准备grpc-go

下载grpc-java

go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
go get -u google.golang.org/grpc
go install github.com/golang/protobuf/protoc-gen-go

protoc-gen-go需要放到环境变量里,让protoc程序能找到。

java 端生成代码

option java_package="com.dtstack.rdslite.task.engine.rpc";

protoc --plugin=protoc-gen-grpc-java=/Users/hx/workspace/java/github/grpc-java/compiler/build/exe/java_plugin/protoc-gen-grpc-java --grpc-java_out="./" "./service.proto"

image

golang 端生成代码

protoc -I=.  -I=/Users/hx/workspace/go/src/ -I=/Users/hx/workspace/go/src/github.com/gogo/protobuf/protobuf/ \
                --go_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,plugins=grpc:test service.proto
                
 #-I=. 指向proto文件位置
 #-I=/Users/hx/workspace/go/src/ #GOPATH
 #-I=/Users/hx/workspace/go/src/github.com/gogo/protobuf/protobuf #依赖头文件
# --go_out= 说明参考https://github.com/gogo/protobuf
#test是生成目录

image

service.proto

syntax = "proto3";

package proto;

import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";

option (gogoproto.goproto_stringer_all) = false;
option (gogoproto.goproto_enum_prefix_all) = false;
option (gogoproto.goproto_getters_all) = false;

option (gogoproto.equal_all) = true;
option (gogoproto.verbose_equal_all) = true;
option (gogoproto.stringer_all) = true;
option (gogoproto.gostring_all) = true;
option (gogoproto.description_all) = true;

option (gogoproto.populate_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;

option (gogoproto.goproto_enum_stringer_all) = false;
option (gogoproto.enum_stringer_all) = true;

option (gogoproto.unsafe_marshaler_all) = false;
option (gogoproto.unsafe_unmarshaler_all) = false;

service EasyAgentService {
    rpc registerSidecar(RegisterRequest) returns (RegisterResponse);
    rpc readyForControl(ControlRequest)  returns (stream ControlResponse);
    rpc reportEvent(Event)               returns (EmptyResponse);
}

service TransferService {
    rpc send(Msg) returns (EmptyResponse);
}

message Msg {
    string id = 1;
    string index = 2;
    string typ = 3;
    bytes jsonBytes = 4;
    bytes key = 5;
}

message EmptyResponse {}

message SidecarRequestHeader {
    bytes id = 1 [(gogoproto.customtype) = "Uuid", (gogoproto.nullable) = false];
    google.protobuf.Timestamp systime = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
}

// Register

message RegisterRequest {
    SidecarRequestHeader H = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
}

message RegisterResponse {

}

// Controlling
message ControlRequest {
    SidecarRequestHeader H = 1 [(gogoproto.nullable) = false, (gogoproto.embed) = true];
}

message ControlResponse {

    enum ControlCmd {
      
    }

    ControlCmd cmd = 1;

    uint32 seqno = 2;

    oneof options {
    }


目录
相关文章
|
8月前
|
Go 数据库
Golang 语言编写 gRPC 实战项目
Golang 语言编写 gRPC 实战项目
81 0
|
8月前
|
存储 JSON Go
Golang 语言 gRPC 服务怎么同时支持 gRPC 和 HTTP 客户端调用?
Golang 语言 gRPC 服务怎么同时支持 gRPC 和 HTTP 客户端调用?
100 0
|
1月前
|
分布式计算 Java Go
golang和java对比
golang和java对比
35 0
|
18天前
|
算法 Java Go
【经典算法】LeetCode 67. 二进制求和(Java/C/Python3/Golang实现含注释说明,Easy)
【经典算法】LeetCode 67. 二进制求和(Java/C/Python3/Golang实现含注释说明,Easy)
9 2
|
18天前
|
算法 Java Go
【经典算法】LeetCode 69. x 的平方根(Java/C/Python3/Golang实现含注释说明,Easy)
【经典算法】LeetCode 69. x 的平方根(Java/C/Python3/Golang实现含注释说明,Easy)
6 1
|
18天前
|
算法 Java Go
【经典算法】LeetCode 64. 最小路径和(Java/C/Python3/Golang实现含注释说明,Easy)
【经典算法】LeetCode 64. 最小路径和(Java/C/Python3/Golang实现含注释说明,Easy)
11 1
|
18天前
|
算法 安全 Java
golang和java对比
golang和java对比
12 1
|
20天前
|
Java Shell 开发工具
03. 【Java教程】在 MacOS 上安装 Java
03. 【Java教程】在 MacOS 上安装 Java
13 1
|
9天前
|
Java
ElasticSearch启动报错 java version is an early-access build ,only use release builds【已解决】
ElasticSearch启动报错 java version is an early-access build ,only use release builds【已解决】
11 0
|
18天前
|
算法 Java Go
【经典算法】LeetCode 35. 搜索插入位置(Java/C/Python3/Golang实现含注释说明,Easy)
【经典算法】LeetCode 35. 搜索插入位置(Java/C/Python3/Golang实现含注释说明,Easy)
8 0