Enhanced support for Nacos weight configuration#11498
Enhanced support for Nacos weight configuration#11498November22 wants to merge 1 commit intoapache:3.2from
Conversation
|
|
||
|
|
||
| private void setWeight(Map<String, String> metadata, double nacosWeight) { | ||
| long weight = Math.round(org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WEIGHT * nacosWeight); |
There was a problem hiding this comment.
- skip if nacos weight has not changed
- We should consider if weight has been set in instance
There was a problem hiding this comment.
There was a problem hiding this comment.
If it is not set in the instance, Nacos sends 1.0 by default, and the calculated result according to the code logic is 100, which is consistent with the default weight of dubbo;
If dubbo has set 200 in url, then set nacos weight as 3, the weight should be 600 as expected.
There was a problem hiding this comment.
If it is not set in the instance, Nacos sends 1.0 by default, and the calculated result according to the code logic is 100, which is consistent with the default weight of dubbo;
If dubbo has set
200in url, then set nacos weight as3, the weight should be600as expected.
- Here, the default weight of dubbo is multiplied by 100, because the weight field type of Nacos is double, so two decimal places can be reserved;
- When the instance and Nacos set the weight at the same time, the weight set by Nacos is used first;(There will be no situation where dubbo sets the weight to 200, Nacos sets the weight to 3, and the calculation result is 600)
There was a problem hiding this comment.
Math.round(org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WEIGHT * nacosWeight) will override the weight from Dubbo provider
There was a problem hiding this comment.
The changes are as shown in the figure (default rounding for double)
This is an good idea. But I am afraid that it would not work in ServiceDiscovery model.
I verified it, it works. When registering, set the weight of dubbo to Nacos; the weight issued by Nacos can be set to Dubbo;
If different service has different weight, it may conflict.
There was a problem hiding this comment.
No, both the reported weight and the issued weight are only related to each instance of the service and will not conflict.
————————
不会的,上报的权重和下发的权重都只会和服务的每个实例相关,并不会冲突。
There was a problem hiding this comment.
For example, for the A interface, I start three instances and set three different weights respectively. The set weights are stored in the org.apache.dubbo.common.URL parameter. When reporting, the weight is obtained from the URL parameter. When sending Obtained from com.alibaba.nacos.api.naming.pojo.Instance#weight
——————
比如A接口,我启动三个实例,分别设置三个不同的权重,设置的权重存储在org.apache.dubbo.common.URL 参数中,上报的时候从URL参数中获取到权重,下发的时候从com.alibaba.nacos.api.naming.pojo.Instance#weight 获取
There was a problem hiding this comment.
Dubbo 的应用级服务发现是把多个服务(接口)聚合为一个应用级的大服务注册到注册中心的,因此如果每个接口权重不一样的话,大服务注册到注册中心的权重就无法确认了
|
Kudos, SonarCloud Quality Gate passed! |
|
|
||
|
|
||
| private void setWeight(Map<String, String> metadata, double nacosWeight) { | ||
| long weight = Math.round(org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WEIGHT * nacosWeight); |
There was a problem hiding this comment.
Math.round(org.apache.dubbo.rpc.cluster.Constants.DEFAULT_WEIGHT * nacosWeight) will override the weight from Dubbo provider
|
Is the feature still not finished and released? |












What is the purpose of the change
support for Nacos weight configuration #11494
Brief changelog
Verifying this change
Checklist