spring boot 整合 Grpc 说明

<!-- 用到的 maven 依赖 -->
<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.21.0</version>
</dependency>

<!-- grpc 构建成服务的依赖 -->
<dependency>
    <groupId>net.devh</groupId>
    <artifactId>grpc-client-spring-boot-starter</artifactId>
    <version>2.1.0.RELEASE</version>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>net.devh</groupId>
    <artifactId>grpc-server-spring-boot-starter</artifactId>
    <version>2.1.0.RELEASE</version>
    <type>pom</type>
</dependency>

<!-- 需要修改构件方式,用来支持 Grpc 生成服务代码 -->
<build>
	<extensions>
		<extension>
			<groupId>kr.motd.maven</groupId>
			<artifactId>os-maven-plugin</artifactId>
			<version>1.5.0.Final</version>
		</extension>
	</extensions>
	<plugins>
		<plugin>
			<groupId>org.xolstice.maven.plugins</groupId>
			<artifactId>protobuf-maven-plugin</artifactId>
			<version>0.5.1</version>
			<configuration>
				<protocArtifact>com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier}</protocArtifact>
				<pluginId>grpc-java</pluginId>
				<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.17.1:exe:${os.detected.classifier}</pluginArtifact>
			</configuration>
			<executions>
				<execution>
					<goals>
						<goal>compile</goal>
						<goal>compile-custom</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

grpc 官网提供的maven/gradle生成代码的实例  https://www.grpc.io/docs/reference/java/generated-code/ 网址最下方

创建 proto 包放置 .proto文件 ,如何构件参考官网 :https://developers.google.cn/protocol-buffers/

proto 文件的位置与 java / resources 同级

c5536e3de931e3e09a8773260792834dce7.jpg

创建好之后运行 mvn compile 命令,或者使用 idea 提供的运行工具

48985b2e3c51d729c356a0fa9fafda57210.jpg

运行 打包如果没有问题 可以在 target 里面找到我们生成的 .class 文件

转载于:https://my.oschina.net/u/3744526/blog/3062132

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值