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
AI 代码解读

mac 环境安装autoconf automake

brew install autoconf
brew install automake
AI 代码解读

build protobuf

cd protobuf
./autogen.sh
./configure
make
sudo make install
AI 代码解读

编译grpc-java

下载grpc-java

git clone https://github.com/grpc/grpc-java.git
git checkout git checkout v1.4.x
AI 代码解读

编译grpc-java

cd grpc-java
./gradlew build
AI 代码解读

生成目标文件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
AI 代码解读

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"
AI 代码解读

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是生成目录
AI 代码解读

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 {
    }


AI 代码解读
目录
打赏
0
相关文章
Golang 语言 gRPC 服务怎么同时支持 gRPC 和 HTTP 客户端调用?
Golang 语言 gRPC 服务怎么同时支持 gRPC 和 HTTP 客户端调用?
237 0
|
6月前
|
Go
Golang语言之gRPC程序设计示例
这篇文章是关于Golang语言使用gRPC进行程序设计的详细教程,涵盖了RPC协议的介绍、gRPC环境的搭建、Protocol Buffers的使用、gRPC服务的编写和通信示例。
163 3
Golang语言之gRPC程序设计示例
Java高级应用开发:AI赋能下的智能代码生成与优化
本文探讨了AI技术,特别是像DeepSeek这样的智能工具,在Java高级应用开发中的应用。AI在代码生成、优化、自动化测试等方面发挥重要作用,可自动生成高质量代码片段、提出优化建议并检测潜在错误,显著提升开发效率与代码质量。未来,AI将进一步推动Java开发的智能化和自动化,为开发者带来全新的开发体验。
【Azure Developer】VS Code打包Java maven Project 遇见 BUILD FAILURE
Unknown lifecycle phase "lean". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>
golang和java对比
golang和java对比
184 0
|
9月前
|
【经典算法】LeetCode 67. 二进制求和(Java/C/Python3/Golang实现含注释说明,Easy)
【经典算法】LeetCode 67. 二进制求和(Java/C/Python3/Golang实现含注释说明,Easy)
147 2
|
9月前
|
【经典算法】LeetCode 69. x 的平方根(Java/C/Python3/Golang实现含注释说明,Easy)
【经典算法】LeetCode 69. x 的平方根(Java/C/Python3/Golang实现含注释说明,Easy)
83 1
|
9月前
|
【经典算法】LeetCode 64. 最小路径和(Java/C/Python3/Golang实现含注释说明,Easy)
【经典算法】LeetCode 64. 最小路径和(Java/C/Python3/Golang实现含注释说明,Easy)
56 1
golang和java对比
golang和java对比
68 1
03. 【Java教程】在 MacOS 上安装 Java
03. 【Java教程】在 MacOS 上安装 Java
103 1

热门文章

最新文章