fantiq commented on issue #15291:
URL: https://github.com/apache/dubbo/issues/15291#issuecomment-3134767474

   
   ## Cause
   
   When `dubbo-compiler` generate java files from a proto file, it uses the two 
variables `originMethodName` and `methodName`.
   
   The value of the variable `originMethodName` is the name of the rpc method, 
the value of the variable `methodName` will lowercase the first letter of the 
rpc method name.
   
   `methodName` is used to fill in the method name of the generated interface 
class.
   `originMethodName` is used to fill the value of the `methodName` parameter 
when instantiating the StubMethodDescriptor object in the generated code.
   
   when the triple protocol registers the rest router, it will traverse the 
interface method and find the StubMethodDescriptor object by the method name.
   
   if the first letter of the RPC method name is capitalized, the 
StubMethodDescriptor object will not be found here, causing the routing 
registration to fail.
   
   e.g.
   
   ```
   service GreeterService {
       rpc SayHello(HelloRequest) returns (HelloReply);
   }
   ```
   
   as defined above, when generate the code, the value of variable 
`originMethodName` whill be `SayHello`,
   the value of variable `methodName` whill be `sayHello`.
   
   ## Solution
   
   ### 1. introduce the option in proto
   
   we can define an option like this:
   
   ```
   extend google.protobuf.MethodOptions {
       string java_method_name = 1001;
   }
   ```
   
   use like this:
   
   ```
   import "org/apache/dubbo/compiler/options.proto";
   service GreeterService {
       rpc SayHello(HelloRequest) returns (HelloReply) {
           option (java_method_name) = "sayHello";
       }
   }
   ```
   
   If the developer uses  `java_method_name` to specify the method name, the 
values of the template variables `originMethodName` and `methodName` when 
generating code will use the same values specified by `java_method_name`.
   
   
   ### 2. associate the value of the `methodName` variable with the 
StubMethodDescriptor object
   
   When i learned about oxsean's work on da8fd19, perhaps we can consider 
storing the value of the variable `methodName` in the `ConcurrentMap<String, 
Object> attributeMap` property of `StubMethodDescriptor` in the generated code.
   
   e.g.
   
   if the rpc defined like this:
   
   ```
   service GreeterService {
       rpc SayHello(HelloRequest) returns (HelloReply);
   }
   ```
   
   The code generated by `dubbo-compiler` is as follows:
   
   ```java
   private static final StubMethodDescriptor sayHelloMethod = new 
StubMethodDescriptor("SayHello",
   org.apache.dubbo.demo.hello.HelloRequest.class, 
org.apache.dubbo.demo.hello.HelloReply.class, MethodDescriptor.RpcType.UNARY,
   obj -> ((Message) obj).toByteArray(), obj -> ((Message) obj).toByteArray(), 
org.apache.dubbo.demo.hello.HelloRequest::parseFrom,
   org.apache.dubbo.demo.hello.HelloReply::parseFrom);
   
   static {
       sayHelloMethod.addAttribute("methodName", "sayHello");
       serviceDescriptor.addMethod(sayHelloMethod);
   }
   ```
   
   When calling the `addMethod(MethodDescriptor)` method, prioritize the method 
name on the `attributeMap`. and it will continue based on da8fd19 .
   
   ## Trade off
   
   solution 1 only requires modifying the `dubbo-compiler`, but requires manual 
settings by the developer.
   solution 2 involves more changes, but users are unaware of them.
   
   any suggestions? @oxsean @paxxie2 @zrlw 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to