Java代码实现grpc服务
1、单纯的使用java和spring的话参考:
https://blog.csdn.net/weixin_33701251/article/details/92600190
2、使用springboot的话 参考:
https://blog.csdn.net/sinat_35477706/article/details/121439364
3、使用eclipse 集成grpc所需的插件会非常麻烦(本人没有安装成功),可参考:
https://www.bbsmax.com/A/n2d9DPnw5D/
https://www.jianshu.com/p/d8b97be3b427
4、使用IDEA 集成grpc所需的插件非常简单,可参考:
https://blog.csdn.net/goldenfish1919/article/details/100097864 (集成插件)
https://blog.csdn.net/amadeus_liu2/article/details/122841423 (简明易懂的代码样例)
集成插件就是为了 使用.proto 文件生成java代码。eclipse即使集成失败,也可以在目录下自己去生成,或则使用IDEA生成也非常简单。
生成代码后 用eclipse或IDEA开发都是一样的。
5、pom文件依赖参考:(grpc-all 应该已经包含了 grpc-server-spring-boot-starter, grpc-client-spring-boot-starter,一种是spring的依赖,一种是springboot方式的依赖,)
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>grpcdemo</artifactId>
<groupId>com.grpc</groupId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>grpc-api</artifactId>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>1.15.1</version>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.0</version>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<protocArtifact>com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<!--suppress UnresolvedMavenProperty -->
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-maven-plugin</artifactId>-->
<!--</plugin>-->
</plugins>
</build>
</project>