|
24 | 24 | import org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery; |
25 | 25 | import org.apache.dubbo.rpc.model.ScopeModelUtil; |
26 | 26 |
|
| 27 | +import java.lang.reflect.Method; |
27 | 28 | import java.util.Collection; |
28 | 29 | import java.util.List; |
29 | 30 | import java.util.Map; |
|
32 | 33 | import org.apache.curator.RetryPolicy; |
33 | 34 | import org.apache.curator.framework.CuratorFramework; |
34 | 35 | import org.apache.curator.framework.CuratorFrameworkFactory; |
| 36 | +import org.apache.curator.framework.CuratorFrameworkFactory.Builder; |
35 | 37 | import org.apache.curator.framework.api.ACLProvider; |
36 | 38 | import org.apache.curator.framework.imps.CuratorFrameworkState; |
37 | 39 | import org.apache.curator.retry.ExponentialBackoffRetry; |
|
43 | 45 |
|
44 | 46 | import static org.apache.curator.x.discovery.ServiceInstance.builder; |
45 | 47 | import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR; |
| 48 | +import static org.apache.dubbo.common.constants.CommonConstants.ZOOKEEPER_ENSEMBLE_TRACKER_KEY; |
46 | 49 | import static org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery.DEFAULT_GROUP; |
47 | 50 | import static org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkParams.BASE_SLEEP_TIME; |
48 | 51 | import static org.apache.dubbo.registry.zookeeper.util.CuratorFrameworkParams.BLOCK_UNTIL_CONNECTED_UNIT; |
@@ -72,6 +75,16 @@ public static CuratorFramework buildCuratorFramework(URL connectionURL, Zookeepe |
72 | 75 | CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() |
73 | 76 | .connectString(connectionURL.getBackupAddress()) |
74 | 77 | .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 | + |
75 | 88 | String userInformation = connectionURL.getUserInformation(); |
76 | 89 | if (StringUtils.isNotEmpty(userInformation)) { |
77 | 90 | builder = builder.authorization("digest", userInformation.getBytes()); |
|
0 commit comments