Skip to content

Commit

Permalink
enhance DynamicCamelliaFeignDynamicOptionGetter
Browse files Browse the repository at this point in the history
  • Loading branch information
caojiajun committed Oct 24, 2023
1 parent c88297d commit 53db8a5
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.netease.nim.camellia.feign.conf;

import com.netease.nim.camellia.core.conf.CamelliaConfig;
import com.netease.nim.camellia.core.discovery.CamelliaServerSelector;
import com.netease.nim.camellia.core.discovery.HashCamelliaServerSelector;
import com.netease.nim.camellia.core.discovery.RandomCamelliaServerSelector;
import com.netease.nim.camellia.feign.client.DynamicOption;
import com.netease.nim.camellia.feign.client.DynamicRouteConfGetter;
import com.netease.nim.camellia.feign.resource.FeignResource;
import com.netease.nim.camellia.tools.circuitbreaker.CircuitBreakerConfig;

import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -34,10 +38,22 @@ public DynamicOption getDynamicOption(long bid, String bgroup) {
circuitBreakerConfig.setRequestVolumeThreshold(() -> globalConfig.getLong(bid, bgroup, "circuit.request.volume.threshold", 20L));
circuitBreakerConfig.setSingleTestIntervalMillis(() -> globalConfig.getLong(bid, bgroup, "circuit.single.test.interval.millis", 5000L));
circuitBreakerConfig.setLogEnable(() -> globalConfig.getBoolean(bid, bgroup, "circuit.log.enable", true));

String string = globalConfig.getString(bid + ".server.selector.policy", "random");
CamelliaServerSelector<FeignResource> serverSelector;
if (string.equalsIgnoreCase("random")) {
serverSelector = new RandomCamelliaServerSelector<>();
} else if (string.equalsIgnoreCase("hash")) {
serverSelector = new HashCamelliaServerSelector<>();
} else {
serverSelector = new RandomCamelliaServerSelector<>();
}

return new DynamicOption.Builder()
.readTimeout(() -> globalConfig.getLong(bid, bgroup, "readTimeout", 3000L), () -> TimeUnit.MILLISECONDS)
.connectTimeout(() -> globalConfig.getLong(bid, bgroup, "connectTimeout", 3000L), () -> TimeUnit.MILLISECONDS)
.circuitBreakerConfig(circuitBreakerConfig)
.serverSelector(serverSelector)
.build();
}

Expand Down

0 comments on commit 53db8a5

Please sign in to comment.