这里描述项目中遇到的问题: 最近启动一个Dubbo项目,启动时候报错,异常信息如下所示: Caused by: java.lang.ClassNotFoundException: org.apache.curator.RetryPolicy
retryPolicy) throws Exception { executeWithRetry(null, consumer, data, retryPolicy); } retryPolicy) throws Exception { return executeWithRetry(callable, null, null, retryPolicy); retryPolicy) throws Exception { // 最大重试次数 Integer maxRetries = retryPolicy.getMaxRetries (5)) .build(); RetryPolicy retryPolicy2 = RetryPolicy.builder() (5)) .build(); RetryPolicy retryPolicy2 = RetryPolicy.builder()
("127.0.0.1:2181", 5000,3000,retryPolicy); curatorFramework.start(); (retryPolicy) //.namespace("base") .build(); client.start(); (retryPolicy) //.namespace("base") .build(); client.start(); (retryPolicy) //.namespace("base") .build(); client.start(); (retryPolicy) //.namespace("base") .build(); client.start();
new NeverRetryPolicy() : new RetryPolicy(request, retryPolicy, this, this.getClientName extends InterceptorRetryPolicy { public RetryPolicy(HttpRequest request, LoadBalancedRetryPolicy new NeverRetryPolicy() : new RetryPolicy(request, retryPolicy, this, this.getClientName extends InterceptorRetryPolicy { public RetryPolicy(HttpRequest request, LoadBalancedRetryPolicy retryPolicy = this.retryPolicy; BackOffPolicy backOffPolicy = this.backOffPolicy; /
int connectionTimeoutMs, RetryPolicy retryPolicy) 其中参数RetryPolicy提供重试策略的接口,可以让⽤户实现⾃定义的重试策略,默认提供了以下实现 通过调用CuratorFramework中的start()方法来启动会话 RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000,3); (); RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000,3); CuratorFramework client = CuratorFrameworkFactory.newClient RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000,3); private static CuratorFramework Client retryPolicy #失败重试策略。
public class Demo { public static void main(String[] args) throws Exception { RetryPolicy retryPolicy retryPolicy(retryPolicy). build(); } ... retryPolicy; ... (RetryPolicy retryPolicy) { this.retryPolicy = retryPolicy; return this; public class Demo { public static void main(String[] args) throws Exception { RetryPolicy retryPolicy
client.close(); } } private static CuratorFramework getClient(){ RetryPolicy () .connectString("127.0.0.0:2181") .retryPolicy(retryPolicy) () .connectString("127.0.0.1:2181") .retryPolicy(retryPolicy) () .connectString("127.0.0.1:2181") .retryPolicy(retryPolicy) () .connectString("127.0.0.1:2181") .retryPolicy(retryPolicy)
, RetryPolicy retryPolicy); 构造方法中的各参数 [up-a76eb940ee60ac9073a4fd42f84dcb87c74.png] connectString:zk的server :失败重试策略 Session会话超时 该方法配置重连retryPolicy以及回话有效时间sessionTimeoutMs,重连就是当客户端与zookeeper 连接异常的时候,如网络波动,断开链接, 重试策略 CuratorFramework通过一个接口RetryPolicy来让用户实现自定义的重试策略。在RetryPolicy来让用户实现自定义的重试策略。 ,唯一需要特别指定单参数是重试机制,从例子上看,你需要使用: RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); CuratorFramework (retryPolicy).namespace("base").build(); 参考资料 https://www.cnblogs.com/a-du/p/9892108.html
public static CuratorFramework newClient(String connectString, RetryPolicy retryPolicy) public static 实例代码: RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000,3); CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181",retryPolicy); client.start(); RetryPolicy ("127.0.0.1:2181", 5000,1000,retryPolicy); client.start(); 其中参数RetryPolicy提供重试策略的接口 实例代码: RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000,3); CuratorFramework client
n:重试的次数 sleepMsBetweenRetries:每次重试间隔的时间 // RetryPolicy retryPolicy = new RetryNTimes(3, 5000 retryPolicy2 = new RetryOneTime(3000); // 永远重试,不推荐使用 // RetryPolicy retryPolicy3 = new ().connectString(zkServerIps) .sessionTimeoutMs(10000).retryPolicy(retryPolicy).build ().connectString(zkServerIps) .sessionTimeoutMs(10000).retryPolicy(retryPolicy).build ().connectString(zkServerIps) .sessionTimeoutMs(10000).retryPolicy(retryPolicy).build
Request URI does not contain a valid hostname: " + originalUri); final LoadBalancedRetryPolicy retryPolicy request, body, execution)); int statusCode = response.getRawStatusCode(); if (retryPolicy RetryTemplate createRetryTemplate(String serviceName, HttpRequest request, LoadBalancedRetryPolicy retryPolicy lbProperties.isEnabled() || retryPolicy == null ? new NeverRetryPolicy() : new InterceptorRetryPolicy(request, retryPolicy, loadBalancer
重试策略
RetryPolicy —— 重试策略接口
public interface RetryPolicy {
/**
* Called when an operation has getRetryPolicy() {
if (this.retryPolicy == null) {
this.retryPolicy = tcpClient.getRetryPolicy retryPolicy;
/** 将Channel保存起来, 可用于在其他非handler的地方发送数据 */
private Channel channel retryPolicy) {
this.host = host;
this.port = port;
this.retryPolicy = retryPolicy 有不同的重连需求的,只需自己实现RetryPolicy接口,然后在创建TcpClient的时候覆盖默认的重连策略即可。
完!!!
重试策略
RetryPolicy —— 重试策略接口
public interface RetryPolicy {
/**
* Called when an operation has getRetryPolicy() {
if (this.retryPolicy == null) {
this.retryPolicy = tcpClient.getRetryPolicy retryPolicy;
/** 将Channel保存起来, 可用于在其他非handler的地方发送数据 */
private Channel channel retryPolicy) {
this.host = host;
this.port = port;
this.retryPolicy = retryPolicy 有不同的重连需求的,只需自己实现RetryPolicy接口,然后在创建TcpClient的时候覆盖默认的重连策略即可。
重试的次数 * sleepMsBetweenRetries:每次重试间隔的时间 */ RetryPolicy retryPolicy = new RetryNTimes(3, 5000); /** * curator链接zookeeper的策略:RetryOneTime * sleepMsBetweenRetry:每次重试间隔的时间 */ RetryPolicy retryPolicy = new RetryOneTime(3000); /** * 永远重试,不推荐使用 */ RetryPolicy retryPolicy = new RetryForever(retryIntervalMs .connectString(zkServerPath) .sessionTimeoutMs(10000).retryPolicy(retryPolicy) (zkServerPath) .sessionTimeoutMs(10000).retryPolicy(retryPolicy) .namespace("workspace
client, String latchPath, String id) 示例代码 package com.secbro.learn.curator; import org.apache.curator.RetryPolicy leaderLatch); } } } private static CuratorFramework getClient() { RetryPolicy () .connectString("127.0.0.1:2181") .retryPolicy(retryPolicy) LeaderSelectorListener listener) 示例代码 package com.secbro.learn.curator; import org.apache.curator.RetryPolicy () .connectString("127.0.0.1:2181") .retryPolicy(retryPolicy)
options = new Request.Options(this.connectTimeout, this.readTimeout); } final LoadBalancedRetryPolicy retryPolicy = 0) { retryTemplate.setListeners(retryListeners); } retryTemplate.setRetryPolicy(retryPolicy == null new NeverRetryPolicy() : new FeignRetryPolicy(request.toHttpRequest(), retryPolicy, this, this.getClientName feignRequest = request.toRequest(); } Response response = request.client().execute(feignRequest, options); if (retryPolicy = null && retryPolicy.retryableStatusCode(response.status())) { byte[] byteArray = response.body() ==
public class Demo { public static void main(String[] args) throws Exception { RetryPolicy retryPolicy public class Demo { public static void main(String[] args) throws Exception { RetryPolicy retryPolicy public class Demo { public static void main(String[] args) throws Exception { RetryPolicy retryPolicy public class Demo { public static void main(String[] args) throws Exception { RetryPolicy retryPolicy public class Demo { public static void main(String[] args) throws Exception { RetryPolicy retryPolicy
Request.Options(this.connectTimeout, this.readTimeout); } final LoadBalancedRetryPolicy retryPolicy retryTemplate.setListeners(retryListeners); } retryTemplate.setRetryPolicy(retryPolicy new NeverRetryPolicy() : new FeignRetryPolicy(request.toHttpRequest(), retryPolicy, this Response response = request.client().execute(feignRequest, options); if (retryPolicy = null && retryPolicy.retryableStatusCode(response.status())) {
zookeeperartifactId> <version>3.5.8version> dependency> import org.apache.curator.RetryPolicy LeaderSelectorTest { private static final String CONNECT_STR="192.168.126.135:2181"; private static RetryPolicy retryPolicy=new ExponentialBackoffRetry( 5*1000, 10 ); private static CuratorFramework curatorFramework appName"); CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(CONNECT_STR, retryPolicy
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); CuratorFramework client = RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); CuratorFramework client = RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); CuratorFramework client = retryPolicy(retryPolicy). build(); 实际上调用的是CuratorFrameworkImpl实例。 = Preconditions.checkNotNull(retryPolicy, "retryPolicy cannot be null"); ensembleProvider =