添加重试
This commit is contained in:
parent
b5068617bb
commit
f1db3e3d1d
@ -341,6 +341,8 @@ public class WvpService {
|
||||
return deviceChannel;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public DeferredResult<JsonResponse<String>> realtimeVideoUrl(String deviceCode) {
|
||||
DeferredResult<JsonResponse<String>> result = new DeferredResult<>(TimeUnit.SECONDS.toMillis(60));
|
||||
result.onTimeout(() -> {
|
||||
@ -354,7 +356,25 @@ public class WvpService {
|
||||
}
|
||||
|
||||
String token = login();
|
||||
Optional<DeviceChannel> deviceChannel = getDeviceChannelByDeviceCode(token, deviceCode);
|
||||
Retryer<Optional<DeviceChannel>> defaultGenericRetryer = RetryerBuilder.<Optional<DeviceChannel>>newBuilder()
|
||||
// 异常就重试
|
||||
.retryIfException()
|
||||
.retryIfRuntimeException()
|
||||
// 重试间隔
|
||||
.withWaitStrategy(WaitStrategies.fixedWait(3, TimeUnit.SECONDS))
|
||||
// 重试次数
|
||||
.withStopStrategy(StopStrategies.stopAfterAttempt(3))
|
||||
.withRetryListener(new RetryListener() {
|
||||
@Override
|
||||
public <V> void onRetry(Attempt<V> attempt) {
|
||||
if (attempt.hasException()) {
|
||||
log.info("异常 {}", attempt.getExceptionCause().getMessage());
|
||||
cache.remove("token");
|
||||
}
|
||||
}
|
||||
}).build();
|
||||
Optional<DeviceChannel> deviceChannel = defaultGenericRetryer.call(() -> getDeviceChannelByDeviceCode(token, deviceCode));
|
||||
|
||||
if (deviceChannel.isEmpty()) {
|
||||
result.setResult(JsonResponse.error(MessageFormat.format("未能获取 设备: {0} 的通道信息", deviceCode)));
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user