-
Notifications
You must be signed in to change notification settings - Fork 26.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Triple Dubbo dual protocol parameters are missing #13158
Comments
Please try use one protocol to see if it work properly? |
should I define interface and POJO separately (using code generated by dubbo plugin now) to make dubbo protocol work? |
The stub mode uses protobuf serialization, but when using the dubbo protocol, other serializations are used, and protobuf objects cannot be serialized, which causes problems. |
It there any way to fix this issue without defining another interface and pojo? |
Have you added the serialization support? <dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-serialization-protobuf</artifactId>
<version>1.0.1</version>
</dependency> |
Not work after adding this dependency. |
Can you provide some detailed error message after adding this dependency? |
Here are one possible solution
<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-serialization-protobuf</artifactId>
<version>1.0.1</version>
<exclusions>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</exclusion>
</exclusions>
</dependency>
public StubMethodDescriptor(String methodName,...
...
// this.returnTypes = new Type[]{requestClass, requestClass};
this.returnTypes = new Type[]{returnClass, returnClass};
...
}
If you have a service message GreeterRequest {
string name = 1;
}
message GreeterReply {
string message = 1;
}
service Greeter{
rpc greet(GreeterRequest) returns (GreeterReply);
} It will generate 3 private static final StubMethodDescriptor greetMethod = new StubMethodDescriptor("greet", [a lot of params]);
private static final StubMethodDescriptor greetAsyncMethod = new StubMethodDescriptor("greet", [a lot of params]);
private static final StubMethodDescriptor greetProxyAsyncMethod = new StubMethodDescriptor("greetAsync", [a lot of params]); Rename the second and third private static final StubMethodDescriptor greetMethod = new StubMethodDescriptor("greet", [a lot of params]);
private static final StubMethodDescriptor greetAsyncMethod = new StubMethodDescriptor("greetAsync", [a lot of params]);
private static final StubMethodDescriptor greetProxyAsyncMethod = new StubMethodDescriptor("greetProxyAsync", [a lot of params]); I haven't tried if this will affect async call, but if don't do that the async
ProtobufUtils.marshaller(GreeterRequest.getDefaultInstance());
ProtobufUtils.marshaller(GreeterReply.getDefaultInstance());
Full demoprovider public class TriOpServer {
public static void main(String[] args) throws IOException {
ServiceConfig<Greeter> service = new ServiceConfig<>();
service.setInterface(Greeter.class);
service.setRef(new TriGreeterImpl());
service.setSerialization("protobuf");
service.setTimeout(1000000);
ProtocolConfig dubboProtocolConfig = new ProtocolConfig(CommonConstants.DUBBO,50063);
dubboProtocolConfig.setSerialization("protobuf");
ApplicationConfig applicationConfig = new ApplicationConfig("tri-stub-server");
applicationConfig.setSerializeCheckStatus("DISABLE");
ProtobufUtils.marshaller(GreeterRequest.getDefaultInstance());
ProtobufUtils.marshaller(GreeterReply.getDefaultInstance());
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(applicationConfig)
.registry(new RegistryConfig("zookeeper://localhost:2181"))
.protocol(new ProtocolConfig(CommonConstants.TRIPLE, 50053))
.protocol(dubboProtocolConfig)
.service(service)
.start()
.await();
}
}
public class TriGreeterImpl extends DubboGreeterTriple.GreeterImplBase {
private static final Logger LOGGER = LoggerFactory.getLogger(org.apache.dubbo.samples.tri.grpc.interop.server.TriGreeterImpl.class);
public TriGreeterImpl() {
}
@Override
public GreeterReply greet(GreeterRequest request) {
LOGGER.info("Server received greet request {}", request);
return GreeterReply.newBuilder()
.setMessage("hello," + request.getName())
.build();
}
} consumer public class TriOpClient {
private static final Logger LOGGER = LoggerFactory.getLogger(TriOpClient.class);
private static Greeter triGreeter;
private static Greeter dubboGreeter;
public static void main(String[] args) throws IOException, InterruptedException {
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
ReferenceConfig<Greeter> tripleRef = new ReferenceConfig<>();
tripleRef.setInterface(Greeter.class);
tripleRef.setProtocol(CommonConstants.TRIPLE);
tripleRef.setProxy(CommonConstants.NATIVE_STUB);
tripleRef.setTimeout(3000);
ReferenceConfig<Greeter> dubboRef = new ReferenceConfig<>();
dubboRef.setInterface(Greeter.class);
dubboRef.setProtocol(CommonConstants.DUBBO);
dubboRef.setProxy(CommonConstants.NATIVE_STUB);
dubboRef.setTimeout(3000000);
ProtobufUtils.marshaller(GreeterRequest.getDefaultInstance());
ProtobufUtils.marshaller(GreeterReply.getDefaultInstance());
ApplicationConfig applicationConfig = new ApplicationConfig("tri-stub-consumer");
applicationConfig.setSerializeCheckStatus("DISABLE");
bootstrap.application(applicationConfig)
.reference(dubboRef)
.reference(tripleRef)
.registry(new RegistryConfig("zookeeper://localhost:2181"))
.start();
dubboGreeter = dubboRef.get();
triGreeter = tripleRef.get();
while (true){
Thread.sleep(1000);
unary(dubboGreeter,"dubbo");
unary(triGreeter,"triple");
}
}
public static void unary(Greeter ref,String name) {
LOGGER.info("Start unary");
final GreeterReply reply = ref.greet(GreeterRequest.newBuilder()
.setName(name)
.build());
LOGGER.info("Unary reply <-{}", reply);
}
} |
Plugin configuration:
Client:
Server:
The text was updated successfully, but these errors were encountered: