# grpc **Repository Path**: zhang-wanpeng/grpc ## Basic Information - **Project Name**: grpc - **Description**: springboot+grpc的简单使用——两个测试demo。(一个grpc_test,另一个springboot_grpc。)两个都是使用springboot+grpc完成,逻辑大致相同;区别:两个proto文件不一样,生成的代码不同。 - **Primary Language**: Java - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2021-11-30 - **Last Updated**: 2024-11-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # grpc #### 介绍 springboot+grpc的简单使用——两个测试demo。(一个grpc_test,另一个springboot_grpc。)两个都是使用springboot+grpc完成,逻辑大致相同;区别:两个proto文件不一样,生成的代码不同。 #### 软件架构 软件架构说明:springboot+grpc #### 安装教程 **① springboot_grpc** 1. 新建一个springboot项目 2. 父工程`pom.xml`导入依赖 ``` 4.0.0 pom grpc_server grpc_cilent grpc_lib org.springframework.boot spring-boot-starter-parent 2.6.0 com.roc.grpc springboot_grpc 0.0.1-SNAPSHOT springboot_grpc Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test io.grpc grpc-netty-shaded 1.14.0 io.grpc grpc-protobuf 1.14.0 io.grpc grpc-stub 1.14.0 kr.motd.maven os-maven-plugin 1.5.0.Final org.springframework.boot spring-boot-maven-plugin org.xolstice.maven.plugins protobuf-maven-plugin 0.5.1 com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier} grpc-java io.grpc:protoc-gen-grpc-java:1.14.0:exe:${os.detected.classifier} compile compile-custom org.apache.maven.plugins maven-compiler-plugin 6 6 ``` 3. 添加`hello.proto`文件 ``` // Copyright 2015 The gRPC Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. syntax = "proto3"; option java_multiple_files = true; option java_package = "io.grpc.examples.helloworld"; option java_outer_classname = "HelloWorldProto"; option objc_class_prefix = "HLW"; 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; } // The response message containing the greetings message HelloReply { string message = 1; } ``` 4. 生成代码 **② grpc_test** 1. 新建一个springboot项目 2. 父工程`pom.xml`导入依赖 ``` 4.0.0 org.springframework.boot spring-boot-starter-parent 2.6.1 com.zwp grpc_test 1.0.0 grpc_test Demo project for Spring Boot 1.8 1.6.1 0.6.1 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test io.github.lognet grpc-spring-boot-starter 3.0.0 junit junit 4.12 test kr.motd.maven os-maven-plugin ${os-maven-plugin.version} org.springframework.boot spring-boot-maven-plugin org.xolstice.maven.plugins protobuf-maven-plugin ${protobuf-maven-plugin.version} com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier} grpc-java io.grpc:protoc-gen-grpc-java:1.16.1:exe:${os.detected.classifier} compile compile-custom ``` 3. 添加`zwp.proto`文件 ``` syntax = "proto3"; option java_multiple_files = true; // option java_package = "io.grpc.examples.helloworld"; // option java_outer_classname = "HelloWorldProto"; // option objc_class_prefix = "HLW"; package com.zwp.grpc.test; // The greeting service definition. service TestGreeter { // Sends a greeting rpc SayHello (Person) returns (Reply) {} rpc Addition (Number) returns (Result) {} } // The request message containing the user's name. message Person { string name = 1; string speak = 2; } // The response message containing the greetings message Reply { string message = 1; } message Number { int32 one = 1; int32 two = 2; } message Result { int32 result = 1; } ``` 4. 生成代码 #### 使用说明 1. xxxx 2. xxxx 3. xxxx #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)