diff --git a/async/README.md b/async/README.md index 1496a1828..702d99f99 100644 --- a/async/README.md +++ b/async/README.md @@ -3,24 +3,95 @@ [[English](README.md) | [中文](README_zh.md)] This sample showcases how to invoke Dubbo services asynchronously with the new -`client`/`server` APIs over the Triple protocol. The client issues both a regular -async call (`GetUser`) and a fire-and-forget style call (`SayHello`) while the -server uses Protobuf serialization to serve Triple requests. Note: This sample -demonstrates the non-blocking nature of async calls; the response can be obtained -through the return value. +`client`/`server` APIs over the Triple protocol. It demonstrates both Go-to-Go +and Java-to-Go async interoperability. -## Run the sample +## Features -1. **Start the provider** +- **Go Client & Server**: Async calls using `client.WithAsync()` +- **Java Client**: Async calls using `CompletableFuture` API +- **Java Server**: Async service implementation with `CompletableFuture` +- **Interoperability**: Java client can call Go server, Go client can call Java server + +## Run Go to Go sample + +1. **Start the Go server** ```bash go run ./async/go-server/cmd/main.go ``` -2. **Start the consumer** +2. **Start the Go client** (connects to Go server by default) ```bash go run ./async/go-client/cmd/main.go ``` The client prints "non-blocking before async callback resp: do something ... " and "test end" logs, demonstrating the non-blocking nature of async calls. + +## Run Java-Go interoperability sample + +This demonstrates **cross-language async calls**: + +- **Go client** → **Java server** +- **Java client** → **Go server** + +### Prerequisites + +- Java 11 or higher +- Maven 3.6+ + +### Build Java modules + +From the `async` directory: + +```bash +mvn clean compile +``` + +### Test: Go client → Java server + +1. **Modify the Go client URL** in `go-client/cmd/main.go`: + + ```go + client.WithClientURL("tri://127.0.0.1:50051"), + ``` + +2. **Start the Java server** (port 50051) + + ```bash + cd java-server + ./run.sh + ``` + +3. **Start the Go client** + + ```bash + go run ./async/go-client/cmd/main.go + ``` + +The Go client will send async requests to the Java server and print "non-blocking before async callback resp: do something ... " logs. + +### Test: Java client → Go server + +1. **Start the Go server** (port 20000) + + ```bash + go run ./async/go-server/cmd/main.go + ``` + +2. **Start the Java client** + + ```bash + cd java-client + ./run.sh + ``` + +The Java client will send async requests to the Go server using `CompletableFuture` callbacks. + +## Port allocation + +- **Go Server**: 20000 +- **Java Server**: 50051 + +Both servers can run simultaneously without conflicts. diff --git a/async/README_zh.md b/async/README_zh.md index b0f7dd113..45d54aad5 100644 --- a/async/README_zh.md +++ b/async/README_zh.md @@ -1,22 +1,96 @@ -# 异步 RPC Dubbo for Dubbo-go +# Dubbo-go 异步 RPC [[English](README.md) | [中文](README_zh.md)] -该示例基于新版 `client` / `server` API 展示 Triple 协议下的 Dubbo 异步调用:客户端 -在发送 `GetUser` 请求后可以继续执行其他逻辑(非阻塞调用),同时也包含 `SayHello` 的单向调用示例。注意:本示例仅演示异步调用的非阻塞特性,实际响应可通过返回值获取。 +本示例展示了如何使用新的 `client`/`server` API 通过 Triple 协议异步调用 Dubbo 服务。 +演示了 Go 和 Java 之间的异步互操作。 -## 运行步骤 +## 功能特性 -1. **启动服务端** +- **Go 客户端和服务端**: 使用 `client.WithAsync()` 实现异步调用 +- **Java 客户端**: 使用 `CompletableFuture` API 实现异步调用 +- **Java 服务端**: 使用 `CompletableFuture` 实现异步服务 +- **互操作性**: Java 客户端可调用 Go 服务端,Go 客户端可调用 Java 服务端 + +## 运行 Go 到 Go 示例 + +1. **启动 Go 服务端** ```bash go run ./async/go-server/cmd/main.go ``` -2. **启动客户端** +2. **启动 Go 客户端**(默认连接 Go 服务端) + + ```bash + go run ./async/go-client/cmd/main.go + ``` + +客户端会打印 "non-blocking before async callback resp: do something ... " 和 "test end" 日志,演示异步调用的非阻塞特性。 + +## 运行 Java-Go 互操作示例 + +演示**跨语言异步调用**: + +- **Go 客户端** → **Java 服务端** +- **Java 客户端** → **Go 服务端** + +### 前置条件 + +- Java 11 或更高版本 +- Maven 3.6+ + +### 构建 Java 模块 + +在 `async` 目录下执行: + +```bash +mvn clean compile +``` + +### 测试:Go 客户端 → Java 服务端 + +1. **修改 Go 客户端 URL**,在 `go-client/cmd/main.go` 中修改: + + ```go + client.WithClientURL("tri://127.0.0.1:50051"), + ``` + +2. **启动 Java 服务端**(端口 50051) + + ```bash + cd java-server + ./run.sh + ``` + +3. **启动 Go 客户端** ```bash go run ./async/go-client/cmd/main.go ``` -客户端会打印"non-blocking before async callback resp: do something ... "和"test end"日志, 演示异步调用的非阻塞特性。 +Go 客户端会向 Java 服务端发送异步请求,并打印 "non-blocking before async callback resp: do something ... " 日志。 + +### 测试:Java 客户端 → Go 服务端 + +1. **启动 Go 服务端**(端口 20000) + + ```bash + go run ./async/go-server/cmd/main.go + ``` + +2. **启动 Java 客户端** + + ```bash + cd java-client + ./run.sh + ``` + +Java 客户端会向 Go 服务端发送异步请求,使用 `CompletableFuture` 回调处理响应。 + +## 端口分配 + +- **Go 服务端**: 20000 +- **Java 服务端**: 50051 + +两个服务端可以同时运行,不会产生端口冲突。 diff --git a/async/java-client/pom.xml b/async/java-client/pom.xml new file mode 100644 index 000000000..767f92b1a --- /dev/null +++ b/async/java-client/pom.xml @@ -0,0 +1,79 @@ + + + + + org.apache.dubbo.samples + async-parent + 1.0.0 + ../pom.xml + + + 4.0.0 + java-async-client + java-async-client + Java client module for async RPC sample + + + + com.google.protobuf + protobuf-java + ${protobuf.version} + + + org.apache.dubbo + dubbo + ${dubbo.version} + + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + + + org.codehaus.mojo + build-helper-maven-plugin + + + generate-sources + + add-source + + + + ${project.build.directory}/generated-sources/protobuf/java + + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + org.apache.dubbo.samples.async.JavaAsyncClient + + + + + diff --git a/async/java-client/run.sh b/async/java-client/run.sh new file mode 100755 index 000000000..788d904a0 --- /dev/null +++ b/async/java-client/run.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +echo "Building Java async client..." +mvn -q clean package + +echo "Starting Java async client..." +mvn -q exec:java -Dexec.mainClass=org.apache.dubbo.samples.async.JavaAsyncClient diff --git a/async/java-client/src/main/java/org/apache/dubbo/samples/async/JavaAsyncClient.java b/async/java-client/src/main/java/org/apache/dubbo/samples/async/JavaAsyncClient.java new file mode 100644 index 000000000..bdee63eef --- /dev/null +++ b/async/java-client/src/main/java/org/apache/dubbo/samples/async/JavaAsyncClient.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.dubbo.samples.async; + +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.bootstrap.DubboBootstrap; +import org.apache.dubbo.samples.async.proto.*; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CountDownLatch; + +public class JavaAsyncClient { + + public static void main(String[] args) throws Exception { + ReferenceConfig userProviderRef = new ReferenceConfig<>(); + userProviderRef.setInterface(UserProvider.class); + userProviderRef.setUrl("tri://127.0.0.1:20000"); + + ReferenceConfig userProviderV2Ref = new ReferenceConfig<>(); + userProviderV2Ref.setInterface(UserProviderV2.class); + userProviderV2Ref.setUrl("tri://127.0.0.1:20000"); + + DubboBootstrap bootstrap = DubboBootstrap.getInstance(); + bootstrap.application(new ApplicationConfig("java-async-client")) + .reference(userProviderRef) + .reference(userProviderV2Ref) + .start(); + + UserProvider userProvider = userProviderRef.get(); + UserProviderV2 userProviderV2 = userProviderV2Ref.get(); + + CountDownLatch latch1 = new CountDownLatch(1); + GetUserRequest getUserReq = GetUserRequest.newBuilder().setId("003").build(); + CompletableFuture future1 = userProvider.getUserAsync(getUserReq); + + System.out.println("async request sent, doing other work..."); + + future1.whenComplete((response, throwable) -> { + if (throwable != null) { + System.err.println("error: " + throwable.getMessage()); + } else { + User user = response.getUser(); + System.out.println("received user: " + user.getName() + ", age: " + user.getAge()); + } + latch1.countDown(); + }); + + CountDownLatch latch2 = new CountDownLatch(1); + SayHelloRequest sayHelloReq = SayHelloRequest.newBuilder().setUserId("002").build(); + CompletableFuture future2 = userProviderV2.sayHelloAsync(sayHelloReq); + + future2.whenComplete((response, throwable) -> { + if (throwable == null) { + System.out.println("sayHello completed"); + } + latch2.countDown(); + }); + + latch1.await(); + latch2.await(); + bootstrap.stop(); + } +} diff --git a/async/java-server/pom.xml b/async/java-server/pom.xml new file mode 100644 index 000000000..d12a5d852 --- /dev/null +++ b/async/java-server/pom.xml @@ -0,0 +1,79 @@ + + + + + org.apache.dubbo.samples + async-parent + 1.0.0 + ../pom.xml + + + 4.0.0 + java-async-server + java-async-server + Java server module for async RPC sample + + + + com.google.protobuf + protobuf-java + ${protobuf.version} + + + org.apache.dubbo + dubbo + ${dubbo.version} + + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + + + org.codehaus.mojo + build-helper-maven-plugin + + + generate-sources + + add-source + + + + ${project.build.directory}/generated-sources/protobuf/java + + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + org.apache.dubbo.samples.async.JavaAsyncServer + + + + + diff --git a/async/java-server/run.sh b/async/java-server/run.sh new file mode 100755 index 000000000..3c68013a0 --- /dev/null +++ b/async/java-server/run.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + +echo "Building Java async server..." +mvn -q clean package + +echo "Starting Java async server on port 50051..." +mvn -q exec:java -Dexec.mainClass=org.apache.dubbo.samples.async.JavaAsyncServer diff --git a/async/java-server/src/main/java/org/apache/dubbo/samples/async/JavaAsyncServer.java b/async/java-server/src/main/java/org/apache/dubbo/samples/async/JavaAsyncServer.java new file mode 100644 index 000000000..6da87b194 --- /dev/null +++ b/async/java-server/src/main/java/org/apache/dubbo/samples/async/JavaAsyncServer.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.dubbo.samples.async; + +import org.apache.dubbo.common.constants.CommonConstants; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.ServiceConfig; +import org.apache.dubbo.config.bootstrap.DubboBootstrap; +import org.apache.dubbo.samples.async.proto.*; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +public class JavaAsyncServer { + + public static void main(String[] args) throws IOException { + ServiceConfig userProviderService = new ServiceConfig<>(); + userProviderService.setInterface(UserProvider.class); + userProviderService.setRef(new UserProviderImpl()); + + ServiceConfig userProviderV2Service = new ServiceConfig<>(); + userProviderV2Service.setInterface(UserProviderV2.class); + userProviderV2Service.setRef(new UserProviderV2Impl()); + + DubboBootstrap bootstrap = DubboBootstrap.getInstance(); + bootstrap.application(new ApplicationConfig("java-async-server")) + .protocol(new ProtocolConfig(CommonConstants.TRIPLE, 50051)) + .service(userProviderService) + .service(userProviderV2Service) + .start(); + + System.out.println("Dubbo triple java async server started on port 50051"); + System.in.read(); + } + + /** + * UserProvider async implementation + */ + static class UserProviderImpl extends DubboUserProviderTriple.UserProviderImplBase { + private static final Map userMap = new HashMap<>(); + + static { + userMap.put("000", User.newBuilder() + .setId("000") + .setName("Alex Stocks") + .setAge(31) + .setTime(System.currentTimeMillis() / 1000) + .setSex(Gender.MAN) + .build()); + + userMap.put("001", User.newBuilder() + .setId("001") + .setName("ZhangSheng") + .setAge(18) + .setTime(System.currentTimeMillis() / 1000) + .setSex(Gender.MAN) + .build()); + + userMap.put("002", User.newBuilder() + .setId("002") + .setName("Lily") + .setAge(20) + .setTime(System.currentTimeMillis() / 1000) + .setSex(Gender.WOMAN) + .build()); + + userMap.put("003", User.newBuilder() + .setId("003") + .setName("Moorse") + .setAge(30) + .setTime(System.currentTimeMillis() / 1000) + .setSex(Gender.WOMAN) + .build()); + } + + @Override + public CompletableFuture getUserAsync(GetUserRequest request) { + return CompletableFuture.supplyAsync(() -> { + System.out.println("Received GetUser request, id: " + request.getId()); + User user = userMap.get(request.getId()); + if (user == null) { + return GetUserResponse.getDefaultInstance(); + } + System.out.println("Returning user: " + user.getName() + ", age: " + user.getAge()); + return GetUserResponse.newBuilder() + .setUser(user) + .build(); + }); + } + } + + /** + * UserProviderV2 async implementation + */ + static class UserProviderV2Impl extends DubboUserProviderV2Triple.UserProviderV2ImplBase { + @Override + public CompletableFuture sayHelloAsync(SayHelloRequest request) { + return CompletableFuture.supplyAsync(() -> { + System.out.println("Received SayHello request, userId: " + request.getUserId()); + return SayHelloResponse.getDefaultInstance(); + }); + } + } +} diff --git a/async/pom.xml b/async/pom.xml new file mode 100644 index 000000000..d27c3b949 --- /dev/null +++ b/async/pom.xml @@ -0,0 +1,97 @@ + + + + 4.0.0 + + org.apache.dubbo.samples + async-parent + 1.0.0 + pom + async-parent + Parent POM for async RPC sample with Java-Go interoperability + + + java-server + java-client + + + + 3.21.7 + 1.51.0 + 3.3.0-beta.2 + 11 + 11 + UTF-8 + + + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + + + + kr.motd.maven + os-maven-plugin + 1.7.0 + + + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} + ${project.build.directory}/generated-sources/protobuf/java + + + dubbo + org.apache.dubbo + dubbo-compiler + ${dubbo.version} + org.apache.dubbo.gen.tri.Dubbo3TripleGenerator + + + ${project.parent.basedir}/proto + + + + + compile + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 3.3.0 + + + + + diff --git a/async/proto/user.pb.go b/async/proto/user.pb.go index ddb50d6a4..543ffd5d7 100644 --- a/async/proto/user.pb.go +++ b/async/proto/user.pb.go @@ -16,8 +16,8 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 -// protoc v3.21.12 +// protoc-gen-go v1.36.10 +// protoc v6.33.1 // source: proto/user.proto package user @@ -27,6 +27,7 @@ import ( protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + unsafe "unsafe" ) const ( @@ -85,24 +86,21 @@ func (Gender) EnumDescriptor() ([]byte, []int) { // User message type User struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Age int32 `protobuf:"varint,3,opt,name=age,proto3" json:"age,omitempty"` + Time int64 `protobuf:"varint,4,opt,name=time,proto3" json:"time,omitempty"` // Unix timestamp in seconds + Sex Gender `protobuf:"varint,5,opt,name=sex,proto3,enum=org.apache.dubbo.samples.async.proto.Gender" json:"sex,omitempty"` unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` - Age int32 `protobuf:"varint,3,opt,name=age,proto3" json:"age,omitempty"` - Time int64 `protobuf:"varint,4,opt,name=time,proto3" json:"time,omitempty"` // Unix timestamp in seconds - Sex Gender `protobuf:"varint,5,opt,name=sex,proto3,enum=user.Gender" json:"sex,omitempty"` + sizeCache protoimpl.SizeCache } func (x *User) Reset() { *x = User{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_user_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_proto_user_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *User) String() string { @@ -113,7 +111,7 @@ func (*User) ProtoMessage() {} func (x *User) ProtoReflect() protoreflect.Message { mi := &file_proto_user_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -165,20 +163,17 @@ func (x *User) GetSex() Gender { // GetUser request type GetUserRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` unknownFields protoimpl.UnknownFields - - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + sizeCache protoimpl.SizeCache } func (x *GetUserRequest) Reset() { *x = GetUserRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_user_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_proto_user_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *GetUserRequest) String() string { @@ -189,7 +184,7 @@ func (*GetUserRequest) ProtoMessage() {} func (x *GetUserRequest) ProtoReflect() protoreflect.Message { mi := &file_proto_user_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -213,20 +208,17 @@ func (x *GetUserRequest) GetId() string { // GetUser response type GetUserResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` unknownFields protoimpl.UnknownFields - - User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` + sizeCache protoimpl.SizeCache } func (x *GetUserResponse) Reset() { *x = GetUserResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_user_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_proto_user_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *GetUserResponse) String() string { @@ -237,7 +229,7 @@ func (*GetUserResponse) ProtoMessage() {} func (x *GetUserResponse) ProtoReflect() protoreflect.Message { mi := &file_proto_user_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -261,20 +253,17 @@ func (x *GetUserResponse) GetUser() *User { // SayHello request type SayHelloRequest struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` + UserId string `protobuf:"bytes,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` unknownFields protoimpl.UnknownFields - - UserId string `protobuf:"bytes,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"` + sizeCache protoimpl.SizeCache } func (x *SayHelloRequest) Reset() { *x = SayHelloRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_user_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_proto_user_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *SayHelloRequest) String() string { @@ -285,7 +274,7 @@ func (*SayHelloRequest) ProtoMessage() {} func (x *SayHelloRequest) ProtoReflect() protoreflect.Message { mi := &file_proto_user_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -309,18 +298,16 @@ func (x *SayHelloRequest) GetUserId() string { // SayHello response (empty for one-way call) type SayHelloResponse struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache + state protoimpl.MessageState `protogen:"open.v1"` unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } func (x *SayHelloResponse) Reset() { *x = SayHelloResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_proto_user_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_proto_user_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *SayHelloResponse) String() string { @@ -331,7 +318,7 @@ func (*SayHelloResponse) ProtoMessage() {} func (x *SayHelloResponse) ProtoReflect() protoreflect.Message { mi := &file_proto_user_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -348,72 +335,60 @@ func (*SayHelloResponse) Descriptor() ([]byte, []int) { var File_proto_user_proto protoreflect.FileDescriptor -var file_proto_user_proto_rawDesc = []byte{ - 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x12, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x70, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, - 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, - 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, - 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x03, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x03, 0x73, 0x65, - 0x78, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0c, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x47, - 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, 0x03, 0x73, 0x65, 0x78, 0x22, 0x20, 0x0a, 0x0e, 0x47, 0x65, - 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x31, 0x0a, 0x0f, - 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x1e, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, - 0x75, 0x73, 0x65, 0x72, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, - 0x2a, 0x0a, 0x0f, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x12, 0x0a, 0x10, 0x53, - 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2a, - 0x1c, 0x0a, 0x06, 0x47, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x12, 0x07, 0x0a, 0x03, 0x4d, 0x41, 0x4e, - 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x57, 0x4f, 0x4d, 0x41, 0x4e, 0x10, 0x01, 0x32, 0x46, 0x0a, - 0x0c, 0x55, 0x73, 0x65, 0x72, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x36, 0x0a, - 0x07, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x12, 0x14, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, - 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, - 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x4b, 0x0a, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x50, 0x72, 0x6f, - 0x76, 0x69, 0x64, 0x65, 0x72, 0x56, 0x32, 0x12, 0x39, 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, - 0x6c, 0x6c, 0x6f, 0x12, 0x15, 0x2e, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x53, 0x61, 0x79, 0x48, 0x65, - 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x75, 0x73, 0x65, - 0x72, 0x2e, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x42, 0x35, 0x5a, 0x33, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65, 0x2f, 0x64, 0x75, 0x62, 0x62, 0x6f, 0x2d, 0x67, 0x6f, - 0x2d, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x2f, 0x61, 0x73, 0x79, 0x6e, 0x63, 0x2f, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x75, 0x73, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, -} +const file_proto_user_proto_rawDesc = "" + + "\n" + + "\x10proto/user.proto\x12$org.apache.dubbo.samples.async.proto\"\x90\x01\n" + + "\x04User\x12\x0e\n" + + "\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" + + "\x04name\x18\x02 \x01(\tR\x04name\x12\x10\n" + + "\x03age\x18\x03 \x01(\x05R\x03age\x12\x12\n" + + "\x04time\x18\x04 \x01(\x03R\x04time\x12>\n" + + "\x03sex\x18\x05 \x01(\x0e2,.org.apache.dubbo.samples.async.proto.GenderR\x03sex\" \n" + + "\x0eGetUserRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\tR\x02id\"Q\n" + + "\x0fGetUserResponse\x12>\n" + + "\x04user\x18\x01 \x01(\v2*.org.apache.dubbo.samples.async.proto.UserR\x04user\"*\n" + + "\x0fSayHelloRequest\x12\x17\n" + + "\auser_id\x18\x01 \x01(\tR\x06userId\"\x12\n" + + "\x10SayHelloResponse*\x1c\n" + + "\x06Gender\x12\a\n" + + "\x03MAN\x10\x00\x12\t\n" + + "\x05WOMAN\x10\x012\x86\x01\n" + + "\fUserProvider\x12v\n" + + "\aGetUser\x124.org.apache.dubbo.samples.async.proto.GetUserRequest\x1a5.org.apache.dubbo.samples.async.proto.GetUserResponse2\x8b\x01\n" + + "\x0eUserProviderV2\x12y\n" + + "\bSayHello\x125.org.apache.dubbo.samples.async.proto.SayHelloRequest\x1a6.org.apache.dubbo.samples.async.proto.SayHelloResponseBh\n" + + "$org.apache.dubbo.samples.async.protoB\tUserProtoP\x01Z3github.com/apache/dubbo-go-samples/async/proto;userb\x06proto3" var ( file_proto_user_proto_rawDescOnce sync.Once - file_proto_user_proto_rawDescData = file_proto_user_proto_rawDesc + file_proto_user_proto_rawDescData []byte ) func file_proto_user_proto_rawDescGZIP() []byte { file_proto_user_proto_rawDescOnce.Do(func() { - file_proto_user_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_user_proto_rawDescData) + file_proto_user_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_proto_user_proto_rawDesc), len(file_proto_user_proto_rawDesc))) }) return file_proto_user_proto_rawDescData } var file_proto_user_proto_enumTypes = make([]protoimpl.EnumInfo, 1) var file_proto_user_proto_msgTypes = make([]protoimpl.MessageInfo, 5) -var file_proto_user_proto_goTypes = []interface{}{ - (Gender)(0), // 0: user.Gender - (*User)(nil), // 1: user.User - (*GetUserRequest)(nil), // 2: user.GetUserRequest - (*GetUserResponse)(nil), // 3: user.GetUserResponse - (*SayHelloRequest)(nil), // 4: user.SayHelloRequest - (*SayHelloResponse)(nil), // 5: user.SayHelloResponse +var file_proto_user_proto_goTypes = []any{ + (Gender)(0), // 0: org.apache.dubbo.samples.async.proto.Gender + (*User)(nil), // 1: org.apache.dubbo.samples.async.proto.User + (*GetUserRequest)(nil), // 2: org.apache.dubbo.samples.async.proto.GetUserRequest + (*GetUserResponse)(nil), // 3: org.apache.dubbo.samples.async.proto.GetUserResponse + (*SayHelloRequest)(nil), // 4: org.apache.dubbo.samples.async.proto.SayHelloRequest + (*SayHelloResponse)(nil), // 5: org.apache.dubbo.samples.async.proto.SayHelloResponse } var file_proto_user_proto_depIdxs = []int32{ - 0, // 0: user.User.sex:type_name -> user.Gender - 1, // 1: user.GetUserResponse.user:type_name -> user.User - 2, // 2: user.UserProvider.GetUser:input_type -> user.GetUserRequest - 4, // 3: user.UserProviderV2.SayHello:input_type -> user.SayHelloRequest - 3, // 4: user.UserProvider.GetUser:output_type -> user.GetUserResponse - 5, // 5: user.UserProviderV2.SayHello:output_type -> user.SayHelloResponse + 0, // 0: org.apache.dubbo.samples.async.proto.User.sex:type_name -> org.apache.dubbo.samples.async.proto.Gender + 1, // 1: org.apache.dubbo.samples.async.proto.GetUserResponse.user:type_name -> org.apache.dubbo.samples.async.proto.User + 2, // 2: org.apache.dubbo.samples.async.proto.UserProvider.GetUser:input_type -> org.apache.dubbo.samples.async.proto.GetUserRequest + 4, // 3: org.apache.dubbo.samples.async.proto.UserProviderV2.SayHello:input_type -> org.apache.dubbo.samples.async.proto.SayHelloRequest + 3, // 4: org.apache.dubbo.samples.async.proto.UserProvider.GetUser:output_type -> org.apache.dubbo.samples.async.proto.GetUserResponse + 5, // 5: org.apache.dubbo.samples.async.proto.UserProviderV2.SayHello:output_type -> org.apache.dubbo.samples.async.proto.SayHelloResponse 4, // [4:6] is the sub-list for method output_type 2, // [2:4] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name @@ -426,73 +401,11 @@ func file_proto_user_proto_init() { if File_proto_user_proto != nil { return } - if !protoimpl.UnsafeEnabled { - file_proto_user_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*User); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_user_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetUserRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_user_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetUserResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_user_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SayHelloRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_proto_user_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*SayHelloResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), - RawDescriptor: file_proto_user_proto_rawDesc, + RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_user_proto_rawDesc), len(file_proto_user_proto_rawDesc)), NumEnums: 1, NumMessages: 5, NumExtensions: 0, @@ -504,7 +417,6 @@ func file_proto_user_proto_init() { MessageInfos: file_proto_user_proto_msgTypes, }.Build() File_proto_user_proto = out.File - file_proto_user_proto_rawDesc = nil file_proto_user_proto_goTypes = nil file_proto_user_proto_depIdxs = nil } diff --git a/async/proto/user.proto b/async/proto/user.proto index 4377d271b..4a04d3ef4 100644 --- a/async/proto/user.proto +++ b/async/proto/user.proto @@ -15,11 +15,20 @@ * limitations under the License. */ +// Generate Go code from this proto file: +// From the async directory, run: +// protoc --go_out=. --go_opt=paths=source_relative \ +// --go-triple_out=. --go-triple_opt=paths=source_relative \ +// ./proto/user.proto + syntax = "proto3"; -package user; +package org.apache.dubbo.samples.async.proto; option go_package = "github.com/apache/dubbo-go-samples/async/proto;user"; +option java_package = "org.apache.dubbo.samples.async.proto"; +option java_multiple_files = true; +option java_outer_classname = "UserProto"; // Gender enumeration enum Gender { diff --git a/async/proto/user.triple.go b/async/proto/user.triple.go index 9059196b4..a6f2885a0 100644 --- a/async/proto/user.triple.go +++ b/async/proto/user.triple.go @@ -25,7 +25,7 @@ const _ = triple_protocol.IsAtLeastVersion0_1_0 const ( // UserProviderName is the fully-qualified name of the UserProvider service. - UserProviderName = "user.UserProvider" + UserProviderName = "org.apache.dubbo.samples.async.proto.UserProvider" ) // These constants are the fully-qualified names of the RPCs defined in this package. They're @@ -37,11 +37,11 @@ const ( // period. const ( // UserProviderGetUserProcedure is the fully-qualified name of the UserProvider's GetUser RPC. - UserProviderGetUserProcedure = "/user.UserProvider/GetUser" + UserProviderGetUserProcedure = "/org.apache.dubbo.samples.async.proto.UserProvider/GetUser" ) const ( // UserProviderV2Name is the fully-qualified name of the UserProviderV2 service. - UserProviderV2Name = "user.UserProviderV2" + UserProviderV2Name = "org.apache.dubbo.samples.async.proto.UserProviderV2" ) // These constants are the fully-qualified names of the RPCs defined in this package. They're @@ -53,7 +53,7 @@ const ( // period. const ( // UserProviderV2SayHelloProcedure is the fully-qualified name of the UserProviderV2's SayHello RPC. - UserProviderV2SayHelloProcedure = "/user.UserProviderV2/SayHello" + UserProviderV2SayHelloProcedure = "/org.apache.dubbo.samples.async.proto.UserProviderV2/SayHello" ) var ( @@ -62,19 +62,19 @@ var ( _ UserProviderV2 = (*UserProviderV2Impl)(nil) ) -// UserProvider is a client for the user.UserProvider service. +// UserProvider is a client for the org.apache.dubbo.samples.async.proto.UserProvider service. type UserProvider interface { GetUser(ctx context.Context, req *GetUserRequest, opts ...client.CallOption) (*GetUserResponse, error) } -// UserProviderV2 is a client for the user.UserProviderV2 service. +// UserProviderV2 is a client for the org.apache.dubbo.samples.async.proto.UserProviderV2 service. type UserProviderV2 interface { SayHello(ctx context.Context, req *SayHelloRequest, opts ...client.CallOption) (*SayHelloResponse, error) } // NewUserProvider constructs a client for the user.UserProvider service. func NewUserProvider(cli *client.Client, opts ...client.ReferenceOption) (UserProvider, error) { - conn, err := cli.DialWithInfo("user.UserProvider", &UserProvider_ClientInfo, opts...) + conn, err := cli.DialWithInfo("org.apache.dubbo.samples.async.proto.UserProvider", &UserProvider_ClientInfo, opts...) if err != nil { return nil, err } @@ -102,7 +102,7 @@ func (c *UserProviderImpl) GetUser(ctx context.Context, req *GetUserRequest, opt // NewUserProviderV2 constructs a client for the user.UserProviderV2 service. func NewUserProviderV2(cli *client.Client, opts ...client.ReferenceOption) (UserProviderV2, error) { - conn, err := cli.DialWithInfo("user.UserProviderV2", &UserProviderV2_ClientInfo, opts...) + conn, err := cli.DialWithInfo("org.apache.dubbo.samples.async.proto.UserProviderV2", &UserProviderV2_ClientInfo, opts...) if err != nil { return nil, err } @@ -129,7 +129,7 @@ func (c *UserProviderV2Impl) SayHello(ctx context.Context, req *SayHelloRequest, } var UserProvider_ClientInfo = client.ClientInfo{ - InterfaceName: "user.UserProvider", + InterfaceName: "org.apache.dubbo.samples.async.proto.UserProvider", MethodNames: []string{"GetUser"}, ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) { dubboCli := dubboCliRaw.(*UserProviderImpl) @@ -137,7 +137,7 @@ var UserProvider_ClientInfo = client.ClientInfo{ }, } var UserProviderV2_ClientInfo = client.ClientInfo{ - InterfaceName: "user.UserProviderV2", + InterfaceName: "org.apache.dubbo.samples.async.proto.UserProviderV2", MethodNames: []string{"SayHello"}, ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) { dubboCli := dubboCliRaw.(*UserProviderV2Impl) @@ -145,7 +145,7 @@ var UserProviderV2_ClientInfo = client.ClientInfo{ }, } -// UserProviderHandler is an implementation of the user.UserProvider service. +// UserProviderHandler is an implementation of the org.apache.dubbo.samples.async.proto.UserProvider service. type UserProviderHandler interface { GetUser(context.Context, *GetUserRequest) (*GetUserResponse, error) } @@ -158,7 +158,7 @@ func SetProviderUserProvider(srv common.RPCService) { dubbo.SetProviderServiceWithInfo(srv, &UserProvider_ServiceInfo) } -// UserProviderV2Handler is an implementation of the user.UserProviderV2 service. +// UserProviderV2Handler is an implementation of the org.apache.dubbo.samples.async.proto.UserProviderV2 service. type UserProviderV2Handler interface { SayHello(context.Context, *SayHelloRequest) (*SayHelloResponse, error) } @@ -172,7 +172,7 @@ func SetProviderUserProviderV2(srv common.RPCService) { } var UserProvider_ServiceInfo = server.ServiceInfo{ - InterfaceName: "user.UserProvider", + InterfaceName: "org.apache.dubbo.samples.async.proto.UserProvider", ServiceType: (*UserProviderHandler)(nil), Methods: []server.MethodInfo{ { @@ -193,7 +193,7 @@ var UserProvider_ServiceInfo = server.ServiceInfo{ }, } var UserProviderV2_ServiceInfo = server.ServiceInfo{ - InterfaceName: "user.UserProviderV2", + InterfaceName: "org.apache.dubbo.samples.async.proto.UserProviderV2", ServiceType: (*UserProviderV2Handler)(nil), Methods: []server.MethodInfo{ {