《Apache Dubbo微服务开发从入门到精通》——通信协议——二、 HTTP/2(Triple)协议(5) https://developer.aliyun.com/article/1224943
2. Triple协议基本示例
这篇教程会通过从零构建一个简单的工程来演示如何基于IDL方式使用Dubbo Triple。
1) 前置条件
• JDK版本>=8
• 已安装Maven
• 已安装并启动Zookeeper
2) 创建工程
a) 创建一个空的maven工程
b) 切换到工程目录
c) 添加Dubbo依赖和插件
在pom.xml中设置JDK版本
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo</artifactId> <version>3.0.8</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-zookeeper-curator5</artifactId> <type>pom</type> <version>3.0.8</version> </dependency> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>3.19.4</version> </dependency> </dependencies> <build> <extensions> <extension> <groupId>kr.motd.maven</groupId> <artifactId>os-maven-plugin</artifactId> <version>1.6.1</version> </extension> </extensions> <plugins> <plugin> <groupId>org.xolstice.maven.plugins</groupId> <artifactId>protobuf-maven-plugin</artifactId> <version>0.6.1</version> <configuration> <protocArtifact>com.google.protobuf:protoc:3.19.4:exe:${os.detected.classifier}</protocArtifact> <protocPlugins> <protocPlugin> <id>dubbo</id> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-compiler</artifactId> <version>0.0.4.1-SNAPSHOT</version> <mainClass>org.apache.dubbo.gen.tri.Dubbo3TripleGenerator</mainClass> </protocPlugin> </protocPlugins> </configuration> <executions> <execution> <goals> <goal>compile</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
d) 添加接口定义文件
src/main/proto/hello.proto,Dubbo使用Protobuf作为IDL。
《Apache Dubbo微服务开发从入门到精通》——通信协议——二、 HTTP/2(Triple)协议(7) https://developer.aliyun.com/article/1224939