Package com.shri.restinpeace
Class RipClientConfig
java.lang.Object
com.shri.restinpeace.RipClientConfig
Per-client settings for
RIP.getClient(Class, RipClientConfig) -
base URL, connect/read timeout, proxy, JSON ObjectMapper, cache,
interceptors, and a default retry policy - for a @RestClient
whose environment differs from every other client's,
since kong.unirest.Unirest's own global config is shared by every
RIP client that doesn't ask for its own. A method's @Timeout overrides this
config's timeout when both are present, the same way an absolute method
URL overrides getBaseUrl(); a method's (or its interface's)
@Retry wins over this
config's getRetry() the same way.
UserApi prodApi = RIP.getClient(UserApi.class, RipClientConfig.builder()
.baseUrl(prodBaseUrl)
.connectTimeoutMillis(2_000)
.readTimeoutMillis(10_000)
.build());
Setting a connect/read timeout, a proxy, or an objectMapper gives
the client its own dedicated kong.unirest.UnirestInstance (its own
connection pool) instead of sharing the app-wide static Unirest
client - a client built with only getBaseUrl() set keeps sharing
the static client, same as RIP.getClient(Class, String).-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic RipClientConfig.Builderbuilder()Starts building a new config.Returns the runtime base URL.Returns this client's bulkhead.Returns this client's external bulkhead provider.getCache()Returns theCachefor this client.Returns whether this client's cache key includes the request's query string.Returns this client's circuit breaker.Returns this client's external circuit breaker provider.Returns the connect timeout.Returns this client's own interceptors.Returns how long this client negatively caches a confirmed404.kong.unirest.ObjectMapperReturns the JSONObjectMapperfor this client.Returns the proxy host.Returns the proxy password.intReturns the proxy port.Returns the proxy username.Returns the read (socket) timeout.getRetry()Returns this client's default retry policy.Returns this client's retry-budget capacity.Returns this client's retry-budget refill window.
-
Method Details
-
builder
Starts building a new config.- Returns:
- a new builder
-
getBaseUrl
Returns the runtime base URL.- Returns:
- the runtime base URL, or
nullto fall back to@BaseUrlon the interface
-
getConnectTimeoutMillis
Returns the connect timeout.- Returns:
- the connect timeout in milliseconds, or
nullto use the shared client's configured default
-
getReadTimeoutMillis
Returns the read (socket) timeout.- Returns:
- the read (socket) timeout in milliseconds, or
nullto use the shared client's configured default
-
getProxyHost
Returns the proxy host.- Returns:
- the proxy host, or
nullif no proxy is configured
-
getProxyPort
public int getProxyPort()Returns the proxy port.- Returns:
- the proxy port; meaningless if
getProxyHost()isnull
-
getProxyUsername
Returns the proxy username.- Returns:
- the proxy username, or
nullfor an unauthenticated proxy
-
getProxyPassword
Returns the proxy password.- Returns:
- the proxy password, or
nullfor an unauthenticated proxy
-
getObjectMapper
public kong.unirest.ObjectMapper getObjectMapper()Returns the JSONObjectMapperfor this client.- Returns:
- the JSON
ObjectMapperfor this client, ornullto use the shared client's configured default (Unirest's own Gson-backedJsonObjectMapper, unless changed viaRIP.setObjectMapper(ObjectMapper))
-
getCache
Returns theCachefor this client.- Returns:
- this client's own
Cache, ornullto fall back to the shared default set viaRIP.setCache(Cache)(or no caching at all, if that's never called either)
-
getCacheKeyIncludesQueryString
Returns whether this client's cache key includes the request's query string.- Returns:
- whether this client's cache key includes the query string, or
nullto fall back to the shared default set viaRIP.setCacheKeyIncludesQueryString(boolean)(which itself defaults totrueif never called)
-
getNegativeCacheTtlMillis
Returns how long this client negatively caches a confirmed404.- Returns:
- the negative-cache TTL in milliseconds, or
nullto fall back to the shared default set viaRIP.setNegativeCacheTtlMillis(long)(which itself defaults to no negative caching at all if never called)
-
getRetryBudgetMaxRetries
Returns this client's retry-budget capacity.- Returns:
- the maximum number of retries available at once (and refilled
back up to over
getRetryBudgetWindowMillis()), ornullfor no cap beyond each call's own@Retry#times()
-
getRetryBudgetWindowMillis
Returns this client's retry-budget refill window.- Returns:
- how long a fully-drained retry budget takes to refill back to
getRetryBudgetMaxRetries(), in milliseconds, ornullif no retry budget is configured
-
getInterceptors
Returns this client's own interceptors.- Returns:
- this client's own interceptors, run in addition to (not instead
of) every globally registered
interceptor- empty if none were set
-
getRetry
Returns this client's default retry policy.- Returns:
- this client's default retry policy, applied to a call whose
method (and interface) has no
@Retryof its own, ornullfor no retrying at all in that case
-
getCircuitBreaker
Returns this client's circuit breaker.- Returns:
- this client's circuit breaker config, or
nullfor no circuit breaker at all (every call always attempted, the default)
-
getCircuitBreakerProvider
Returns this client's external circuit breaker provider.- Returns:
- this client's
CircuitBreakerProvider, ornullif this client instead usesgetCircuitBreaker()(or neither is set)
-
getBulkhead
Returns this client's bulkhead.- Returns:
- this client's bulkhead config, or
nullfor no concurrency cap at all (the default)
-
getBulkheadProvider
Returns this client's external bulkhead provider.- Returns:
- this client's
BulkheadProvider, ornullif this client instead usesgetBulkhead()(or neither is set)
-