GitHub user SpringStudent closed a discussion: [Q/A]The parameters in Dubbo's
RPC calls are passed by value.
### Pre-check
- [X] I am sure that all the content I provide is in English.
### Apache Dubbo Component
Java SDK (apache/dubbo)
### Details
While working on Service A today, I found that the return value of a method in
Service B did not meet the requirements. However, this interface method is
already referenced in many places, so changing its return value would
inevitably affect multiple consumers.
Then I looked at the method signature and noticed that it takes a Map as a
parameter. So I thought—why not modify this method in Service B to put the
result that Service A needs into the input Map? That way, after Service A calls
Service B, it can retrieve the result from the Map. Here's some pseudocode:
```
// Service A
Map<String, Object> map = new HashMap<>();
map.put("id", "xxx");
serviceB.invoke(map);
System.out.println(map.get("serviceA"));
// Service B
String invoke(Map map) {
map.put("serviceA", "result");
return "aaa";
}
```
This raises a question: Since RPC method parameters are passed by value, is it
possible to support pass-by-reference? If not, then the description that RPC
can call remote services just like local methods might be somewhat
misleading(**The parameters in Java method local calls support both value
passing and reference passing**).
译文
今天在写服务A时,发现服务B的方法返回值不满足要求。这个接口方法已经被很多地方引用,如果修改方法返回值势必会影响多个消费方。于是看了下方法签名,方法的参数传递的是一个Map对象,于是就设想调整一下服务B的该方法,将服务A想要的结果放到入参Map不就行了吗,这样服务A的调用服务B结束再从参数中获取服务B放入的结果不就行了吗,伪代码如下
```
//serviceA
Map<String,Object> map = new HashMap();
map.put("id","xxx");
serviceB.invoke(map);
System.out.printlin(map.get("serviceA"));
//serviceB
String invoke(Map map){
map.put("serviceA","result")
return "aaa";
}
```
这就涉及到一个问题,Rpc的方法调用参数是值传递,那么是否可以支持方法调用参数为引用传递。如果不能做到,那么像调用本地方法一样调用远程服务的描述是否有些歧义(**java方法本地调用参数既支持值传递也支持引用传递的**)。
### Code of Conduct
- [X] I agree to follow this project's [Code of
Conduct](https://www.apache.org/foundation/policies/conduct)
GitHub link: https://github.com/apache/dubbo/discussions/15372
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]