Skip to content

Commit

Permalink
Merge pull request #518 from Assassinxc/add-timeout-option-for-etcd-k…
Browse files Browse the repository at this point in the history
…vget

Add timeout option for etcd kvClient get
  • Loading branch information
KamToHung authored Jan 16, 2025
2 parents 855570d + 03f5157 commit 2422c58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public static class Etcd {
private String authority = "ssl";

private String key;

private long timeout = 30000L;
}

private static class Holder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/**
* @author Redick01
Expand Down Expand Up @@ -97,7 +98,7 @@ public static Map<Object, Object> getConfigMap(final DtpProperties.Etcd etcd, fi
KeyValue keyValue = client(etcd)
.getKVClient()
.get(bytesOf(etcd.getKey()))
.get()
.get(etcd.getTimeout(), TimeUnit.MILLISECONDS)
.getKvs()
.get(0);
if (Objects.isNull(keyValue)) {
Expand All @@ -111,7 +112,7 @@ public static Map<Object, Object> getConfigMap(final DtpProperties.Etcd etcd, fi
GetResponse response = client(etcd)
.getKVClient()
.get(key, getOption)
.get();
.get(etcd.getTimeout(), TimeUnit.MILLISECONDS);
List<KeyValue> keyValues = response.getKvs();
Map<Object, Object> finalResultMap = resultMap;
keyValues.forEach(keyValue -> {
Expand Down

0 comments on commit 2422c58

Please # to comment.