Class Consul.Builder

java.lang.Object
org.kiwiproject.consul.Consul.Builder
Enclosing class:
Consul

public static class Consul.Builder extends Object
Builder for Consul client objects.
  • Method Details

    • withUrl

      public Consul.Builder withUrl(URL url)
      Sets the URL from a URL object.
      Parameters:
      url - The Consul agent URL.
      Returns:
      The builder.
    • withHttps

      public Consul.Builder withHttps(boolean withHttps)
      Use HTTPS connections for all requests.
      Parameters:
      withHttps - Set to true to use https for all Consul requests.
      Returns:
      The builder.
    • withPing

      public Consul.Builder withPing(boolean ping)
      Instructs the builder that the AgentClient should attempt a ping before returning the Consul instance
      Parameters:
      ping - Whether the ping should be done or not
      Returns:
      The builder.
    • withBasicAuth

      public Consul.Builder withBasicAuth(String username, String password)
      Sets the username and password to be used for basic authentication
      Parameters:
      username - the value of the username
      password - the value of the password
      Returns:
      The builder.
    • withTokenAuth

      public Consul.Builder withTokenAuth(String token)
      Sets the token used for authentication
      Parameters:
      token - the token
      Returns:
      The builder.
    • withAclToken

      public Consul.Builder withAclToken(String token)
      Sets the ACL token to be used with Consul
      Parameters:
      token - the value of the token
      Returns:
      The builder.
    • withHeaders

      public Consul.Builder withHeaders(Map<String,String> headers)
      Sets headers to be included with each Consul request.
      Parameters:
      headers - Map of headers.
      Returns:
      The builder.
    • withConsulBookend

      public Consul.Builder withConsulBookend(ConsulBookend consulBookend)
      Attaches a ConsulBookend to each Consul request. This can be used for gathering metrics, timings or debugging.
      Parameters:
      consulBookend - The bookend implementation.
      Returns:
      The builder.
      See Also:
    • withHostAndPort

      public Consul.Builder withHostAndPort(com.google.common.net.HostAndPort hostAndPort)
      Sets the URL from a HostAndPort object.
      Parameters:
      hostAndPort - The Consul agent host and port.
      Returns:
      The builder.
    • withMultipleHostAndPort

      public Consul.Builder withMultipleHostAndPort(Collection<com.google.common.net.HostAndPort> hostAndPort, long blacklistTimeInMillis)
      Sets the list of hosts to contact if the current request target is unavailable. When the call to a particular URL fails for any reason, the next HostAndPort specified is used to retry the request. This will continue until all urls are exhausted.
      Parameters:
      hostAndPort - A collection of HostAndPort that define the list of Consul agent addresses to use.
      blacklistTimeInMillis - The timeout (in milliseconds) to blacklist a particular HostAndPort before trying to use it again.
      Returns:
      The builder.
    • withFailoverInterceptor

      public Consul.Builder withFailoverInterceptor(ConsulFailoverStrategy strategy)
      Constructs a failover interceptor with the given ConsulFailoverStrategy.
      Parameters:
      strategy - The strategy to use.
      Returns:
      The builder.
    • withUrl

      public Consul.Builder withUrl(String url)
      Sets the URL from a string.
      Parameters:
      url - The Consul agent URL.
      Returns:
      The builder.
    • withSslContext

      public Consul.Builder withSslContext(SSLContext sslContext)
      Sets the SSLContext for the client.
      Parameters:
      sslContext - The SSL context for HTTPS agents.
      Returns:
      The builder.
    • withTrustManager

      public Consul.Builder withTrustManager(X509TrustManager trustManager)
      Sets the X509TrustManager for the client.
      Parameters:
      trustManager - The SSL trust manager for HTTPS agents.
      Returns:
      The builder.
    • withHostnameVerifier

      public Consul.Builder withHostnameVerifier(HostnameVerifier hostnameVerifier)
      Sets the HostnameVerifier for the client.
      Parameters:
      hostnameVerifier - The hostname verifier to use.
      Returns:
      The builder.
    • withProxy

      public Consul.Builder withProxy(Proxy proxy)
      Sets the Proxy for the client.
      Parameters:
      proxy - The proxy to use.
      Returns:
      The builder
    • withConnectTimeoutMillis

      public Consul.Builder withConnectTimeoutMillis(long timeoutMillis)
      Connect timeout for OkHttpClient
      Parameters:
      timeoutMillis - timeout values in milliseconds
      Returns:
      The builder
    • withReadTimeoutMillis

      public Consul.Builder withReadTimeoutMillis(long timeoutMillis)
      Read timeout for OkHttpClient
      Parameters:
      timeoutMillis - timeout value in milliseconds
      Returns:
      The builder
    • withWriteTimeoutMillis

      public Consul.Builder withWriteTimeoutMillis(long timeoutMillis)
      Write timeout for OkHttpClient
      Parameters:
      timeoutMillis - timeout value in milliseconds
      Returns:
      The builder
    • withExecutorService

      public Consul.Builder withExecutorService(ExecutorService executorService)
      Sets the ExecutorService to be used by the internal task dispatcher.

      By default, an ExecutorService is created internally. In this case, it will not be customizable nor manageable by the user application. It can only be shutdown by the Consul.destroy() method.

      When an application needs to be able to customize the ExecutorService parameters, and/or manage its lifecycle, it can provide an instance of ExecutorService to the Builder. In that case, this ExecutorService will be used instead of creating one internally.

      Parameters:
      executorService - The ExecutorService to be injected in the internal task dispatcher.
      Returns:
      The builder
    • withConnectionPool

      public Consul.Builder withConnectionPool(okhttp3.ConnectionPool connectionPool)
      Sets the ConnectionPool to be used by OkHttp Client

      By default, an ConnectionPool is created internally. In this case, it will not be customizable nor manageable by the user application. It can only be shutdown by the Consul.destroy() method.

      When an application needs to be able to customize the ConnectionPool parameters, and/or manage its lifecycle, it can provide an instance of ConnectionPool to the Builder. In that case, this ConnectionPool will be used instead of creating one internally.

      Parameters:
      connectionPool - The ConnectionPool to be injected in the internal OkHttpClient
      Returns:
      The builder
    • withClientConfiguration

      public Consul.Builder withClientConfiguration(ClientConfig clientConfig)
      Sets the configuration for the clients. The configuration will fall back on the library default configuration if elements are not set.
      Parameters:
      clientConfig - the configuration to use.
      Returns:
      The Builder
    • withClientEventCallback

      public Consul.Builder withClientEventCallback(ClientEventCallback callback)
      Sets the event callback for the clients. The callback will be called by the consul client after each event.
      Parameters:
      callback - the callback to call.
      Returns:
      The Builder
    • build

      public Consul build()
      Constructs a new Consul client.
      Returns:
      A new Consul client.