Skip to content

Commit a9fedd5

Browse files
authored
feat: Support disable Curator EnsembleTracker (#14597)
* feat: Support disable Curator EnsembleTracker Support disable Curator EnsembleTracker and compatible with curator4 * Use Throwable instead detail Exception
1 parent 1190033 commit a9fedd5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/util/CuratorFrameworkUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery;
2525
import org.apache.dubbo.rpc.model.ScopeModelUtil;
2626

27+
import java.lang.reflect.Method;
2728
import java.util.Collection;
2829
import java.util.List;
2930
import java.util.Map;
@@ -32,6 +33,7 @@
3233
import org.apache.curator.RetryPolicy;
3334
import org.apache.curator.framework.CuratorFramework;
3435
import org.apache.curator.framework.CuratorFrameworkFactory;
36+
import org.apache.curator.framework.CuratorFrameworkFactory.Builder;
3537
import org.apache.curator.framework.api.ACLProvider;
3638
import org.apache.curator.framework.imps.CuratorFrameworkState;
3739
import org.apache.curator.retry.ExponentialBackoffRetry;
@@ -43,6 +45,7 @@
4345

4446
import static org.apache.curator.x.discovery.ServiceInstance.builder;
4547
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
48+
import static org.apache.dubbo.common.constants.CommonConstants.ZOOKEEPER_ENSEMBLE_TRACKER_KEY;
4649
import static org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery.DEFAULT_GROUP;
4750
import static org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkParams.BASE_SLEEP_TIME;
4851
import static org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkParams.BLOCK_UNTIL_CONNECTED_UNIT;
@@ -72,6 +75,16 @@ public static CuratorFramework buildCuratorFramework(URL connectionURL, Zookeepe
7275
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
7376
.connectString(connectionURL.getBackupAddress())
7477
.retryPolicy(buildRetryPolicy(connectionURL));
78+
try {
79+
// use reflect to check method exist to compatibility with curator4, can remove in dubbo3.3 and direct call
80+
// the method because 3.3 only supported curator5
81+
Class<? extends Builder> builderClass = builder.getClass();
82+
Method ignore = builderClass.getMethod("ensembleTracker", boolean.class);
83+
boolean ensembleTrackerFlag = connectionURL.getParameter(ZOOKEEPER_ENSEMBLE_TRACKER_KEY, true);
84+
builder.ensembleTracker(ensembleTrackerFlag);
85+
} catch (Throwable ignore) {
86+
}
87+
7588
String userInformation = connectionURL.getUserInformation();
7689
if (StringUtils.isNotEmpty(userInformation)) {
7790
builder = builder.authorization("digest", userInformation.getBytes());

0 commit comments

Comments
 (0)