-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from FrogDevelopment/feature/improvements
[consul] have a dedicated client for blocking queries
- Loading branch information
Showing
16 changed files
with
147 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/com/frogdevelopment/micronaut/consul/watch/WatchConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.frogdevelopment.micronaut.consul.watch; | ||
|
||
import java.time.Duration; | ||
import java.util.Optional; | ||
|
||
import io.micronaut.context.annotation.ConfigurationProperties; | ||
import io.micronaut.core.annotation.Nullable; | ||
import io.micronaut.discovery.consul.ConsulConfiguration; | ||
import io.micronaut.discovery.consul.condition.RequiresConsul; | ||
import io.micronaut.http.client.HttpClientConfiguration; | ||
|
||
@RequiresConsul | ||
@ConfigurationProperties(WatchConfiguration.PREFIX) | ||
public class WatchConfiguration extends HttpClientConfiguration { | ||
|
||
public static final String EXPR_CONSUL_WATCH_RETRY_COUNT = "${" + WatchConfiguration.PREFIX + ".retry-count:3}"; | ||
public static final String EXPR_CONSUL_WATCH_RETRY_DELAY = "${" + WatchConfiguration.PREFIX + ".retry-delay:1s}"; | ||
|
||
/** | ||
* The default block timeout in minutes. | ||
*/ | ||
public static final long DEFAULT_BLOCK_TIMEOUT_MINUTES = 10; | ||
|
||
public static final long DEFAULT_WATCH_DELAY_MILLISECONDS = 500; | ||
|
||
/** | ||
* The prefix to use for all Consul settings. | ||
*/ | ||
public static final String PREFIX = "consul.watch"; | ||
|
||
private Duration readTimeout = Duration.ofMinutes(DEFAULT_BLOCK_TIMEOUT_MINUTES); | ||
private Duration watchDelay = Duration.ofSeconds(DEFAULT_WATCH_DELAY_MILLISECONDS); | ||
|
||
private final ConsulConfiguration consulConfiguration; | ||
|
||
public WatchConfiguration(final ConsulConfiguration consulConfiguration) { | ||
super(consulConfiguration); | ||
this.consulConfiguration = consulConfiguration; | ||
} | ||
|
||
@Override | ||
public ConnectionPoolConfiguration getConnectionPoolConfiguration() { | ||
return consulConfiguration.getConnectionPoolConfiguration(); | ||
} | ||
|
||
@Override | ||
public Optional<Duration> getReadTimeout() { | ||
return Optional.ofNullable(readTimeout); | ||
} | ||
|
||
@Override | ||
public void setReadTimeout(@Nullable Duration readTimeout) { | ||
this.readTimeout = readTimeout; | ||
} | ||
|
||
public Duration getWatchDelay() { | ||
return watchDelay; | ||
} | ||
|
||
/** | ||
* Sets the watch delay before each call to avoid flooding. Default value ({@value #DEFAULT_WATCH_DELAY_MILLISECONDS} milliseconds). | ||
* | ||
* @param watchDelay The read timeout | ||
*/ | ||
public void setWatchDelay(Duration watchDelay) { | ||
this.watchDelay = watchDelay; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
src/main/java/com/frogdevelopment/micronaut/consul/watch/client/IndexConsulClient.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/main/java/com/frogdevelopment/micronaut/consul/watch/client/WatchConsulClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.frogdevelopment.micronaut.consul.watch.client; | ||
|
||
import java.util.List; | ||
|
||
import com.frogdevelopment.micronaut.consul.watch.WatchConfiguration; | ||
|
||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.core.annotation.Nullable; | ||
import io.micronaut.discovery.consul.client.v1.ConsulClient; | ||
import io.micronaut.http.annotation.Get; | ||
import io.micronaut.http.annotation.QueryValue; | ||
import io.micronaut.http.client.annotation.Client; | ||
import io.micronaut.retry.annotation.Retryable; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Requires(beans = WatchConfiguration.class) | ||
@Client(id = ConsulClient.SERVICE_ID, path = "/v1", configuration = WatchConfiguration.class) | ||
public interface WatchConsulClient { | ||
|
||
@Get(uri = "/kv/{+key}?{&recurse}{&index}", single = true) | ||
@Retryable( | ||
attempts = WatchConfiguration.EXPR_CONSUL_WATCH_RETRY_COUNT, | ||
delay = WatchConfiguration.EXPR_CONSUL_WATCH_RETRY_DELAY | ||
) | ||
Mono<List<KeyValue>> watchValues(String key, @Nullable @QueryValue Boolean recurse, @Nullable @QueryValue Integer index); | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/com/frogdevelopment/micronaut/consul/watch/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.