Class RipClientConfig

java.lang.Object
com.shri.restinpeace.RipClientConfig

public final class RipClientConfig extends Object
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).
  • Method Details

    • builder

      public static RipClientConfig.Builder builder()
      Starts building a new config.
      Returns:
      a new builder
    • getBaseUrl

      public String getBaseUrl()
      Returns the runtime base URL.
      Returns:
      the runtime base URL, or null to fall back to @BaseUrl on the interface
    • getConnectTimeoutMillis

      public Integer getConnectTimeoutMillis()
      Returns the connect timeout.
      Returns:
      the connect timeout in milliseconds, or null to use the shared client's configured default
    • getReadTimeoutMillis

      public Integer getReadTimeoutMillis()
      Returns the read (socket) timeout.
      Returns:
      the read (socket) timeout in milliseconds, or null to use the shared client's configured default
    • getProxyHost

      public String getProxyHost()
      Returns the proxy host.
      Returns:
      the proxy host, or null if no proxy is configured
    • getProxyPort

      public int getProxyPort()
      Returns the proxy port.
      Returns:
      the proxy port; meaningless if getProxyHost() is null
    • getProxyUsername

      public String getProxyUsername()
      Returns the proxy username.
      Returns:
      the proxy username, or null for an unauthenticated proxy
    • getProxyPassword

      public String getProxyPassword()
      Returns the proxy password.
      Returns:
      the proxy password, or null for an unauthenticated proxy
    • getObjectMapper

      public kong.unirest.ObjectMapper getObjectMapper()
      Returns the JSON ObjectMapper for this client.
      Returns:
      the JSON ObjectMapper for this client, or null to use the shared client's configured default (Unirest's own Gson-backed JsonObjectMapper, unless changed via RIP.setObjectMapper(ObjectMapper))
    • getCache

      public Cache getCache()
      Returns the Cache for this client.
      Returns:
      this client's own Cache, or null to fall back to the shared default set via RIP.setCache(Cache) (or no caching at all, if that's never called either)
    • getCacheKeyIncludesQueryString

      public Boolean 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 null to fall back to the shared default set via RIP.setCacheKeyIncludesQueryString(boolean) (which itself defaults to true if never called)
    • getNegativeCacheTtlMillis

      public Long getNegativeCacheTtlMillis()
      Returns how long this client negatively caches a confirmed 404.
      Returns:
      the negative-cache TTL in milliseconds, or null to fall back to the shared default set via RIP.setNegativeCacheTtlMillis(long) (which itself defaults to no negative caching at all if never called)
    • getRetryBudgetMaxRetries

      public Integer getRetryBudgetMaxRetries()
      Returns this client's retry-budget capacity.
      Returns:
      the maximum number of retries available at once (and refilled back up to over getRetryBudgetWindowMillis()), or null for no cap beyond each call's own @Retry#times()
    • getRetryBudgetWindowMillis

      public Long 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, or null if no retry budget is configured
    • getInterceptors

      public List<RequestInterceptor> 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

      public RetryConfig 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 @Retry of its own, or null for no retrying at all in that case
    • getCircuitBreaker

      public CircuitBreakerConfig getCircuitBreaker()
      Returns this client's circuit breaker.
      Returns:
      this client's circuit breaker config, or null for no circuit breaker at all (every call always attempted, the default)
    • getCircuitBreakerProvider

      public CircuitBreakerProvider getCircuitBreakerProvider()
      Returns this client's external circuit breaker provider.
      Returns:
      this client's CircuitBreakerProvider, or null if this client instead uses getCircuitBreaker() (or neither is set)
    • getBulkhead

      public BulkheadConfig getBulkhead()
      Returns this client's bulkhead.
      Returns:
      this client's bulkhead config, or null for no concurrency cap at all (the default)
    • getBulkheadProvider

      public BulkheadProvider getBulkheadProvider()
      Returns this client's external bulkhead provider.
      Returns:
      this client's BulkheadProvider, or null if this client instead uses getBulkhead() (or neither is set)