简体   繁体   English

Java的gRPC protobuf生成器-生成的不同代码

[英]gRPC protobuf generator for Java - different generated code

I look through different tutorials about gRPC and use it in Java, but code I get after protoc launch and code in tutorials are quite different. 我浏览了有关gRPC的不同教程,并在Java中使用了它,但是protoc启动后得到的代码与教程中的代码完全不同。 For instance, I look video from Ray Tsang and service interface looks like GreetingServiceGrpc.GreetingService, but when Itry to generate my own, I get GreetingService.Interface. 例如,我从曾荫权视频 ,服务接口看起来像GreetingServiceGrpc.GreetingService,但是当Itry生成自己的视频时,我得到GreetingService.Interface。 Also, there's no effect from 'stream' keyword in my generated code, so I don't understand how can I use it. 另外,在生成的代码中'stream'关键字没有任何作用,因此我不知道如何使用它。 I have a feeling that I use some wrong tool at all or at least another version of it. 我感觉我完全使用了错误的工具,或者至少使用了另一个版本。 Please, point me the right way :) 请指出正确的方法:)

protoc.exe --version  // 3.0.0

protoc.exe by itself only generates protobuf message classes. protoc.exe本身仅生成protobuf消息类。 To generate gRPC code, it needs to work with the gRPC code generator plugin. 要生成gRPC代码,它需要与gRPC代码生成器插件一起使用。 The easiest way to use it is through protobuf-maven-plugin or protobuf-gradle-plugin , which will download protoc and the gRPC code-gen plugin and run them for you. 使用它最简单的方法就是通过protobuf-maven-pluginprotobuf-gradle-plugin ,这将下载protoc和GRPC代码生成插件,并运行它们。 You can find example snippets for the Maven/Gradle plugins from the README of gRPC Java. 您可以从gRPC Java的自述文件中找到Maven / Gradle插件的示例片段。 There is also a stand-alone example project that uses the Gradle plugin. 还有一个使用Gradle插件的独立示例项目

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 grpc protobuf java中的NoSuchMethodException和NoClassDefFoundError - NoSuchMethodException and NoClassDefFoundError in grpc protobuf java 将 protobuf(由 grpc 生成)转换为 Android 中的 JSON - Convert a protobuf ( generated by grpc ) to JSON in Android protobuf生成的Maven Java编译器错误代码:不兼容的返回类型 - Maven Java compiler errors for protobuf generated Code: incompatible return types 在 Grpc 生成的 java 代码中设置嵌套属性值的更简单方法 - An easier way of setting nested properties values in Grpc generated java code 用于Protobuf编译器的gRPC Java Codegen插件 - gRPC Java Codegen Plugin for Protobuf Compiler 适用于gRPC / protobuf的Java IDL(协议缓冲区) - Java IDL for gRPC / protobuf (Protocl Buffers) 如何直接从 protobuf 创建 GRPC 客户端而不将其编译成 java 代码 - How to create GRPC client directly from protobuf without compiling it into java code 如何配置 VS Code 和 Gradle 以将生成的 Java 代码与 Gradle Protobuf 插件一起使用? - How do I configure VS Code and Gradle to use generated Java code with the Gradle Protobuf plugin? 尝试生成 Java Protobuf 代码时出现“包 io.grpc 不存在”和“仅从类和接口静态导入” - “package io.grpc does not exist” and “static import only from classes and interfaces” when trying to generate Java Protobuf code Java生成的Protobuf反射,但没有找到类 - Java reflection on generated Protobuf but class not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM