Class Consul.Builder

  • Enclosing class:
    Consul

    public static class Consul.Builder
    extends java.lang.Object
    Builder for Consul client objects.
    • Method Detail

      • withUrl

        public Consul.Builder withUrl​(java.net.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​(java.lang.String username,
                                            java.lang.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​(java.lang.String token)
        Sets the token used for authentication
        Parameters:
        token - the token
        Returns:
        The builder.
      • withAclToken

        public Consul.Builder withAclToken​(java.lang.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​(java.util.Map<java.lang.String,​java.lang.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. {@see ConsulBookend}
        Parameters:
        consulBookend - The bookend implementation.
        Returns:
        The builder.
      • 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​(java.util.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 exhuasted.
        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.
      • withUrl

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

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

        public Consul.Builder withTrustManager​(javax.net.ssl.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​(javax.net.ssl.HostnameVerifier hostnameVerifier)
        Sets the HostnameVerifier for the client.
        Parameters:
        hostnameVerifier - The hostname verifier to use.
        Returns:
        The builder.
      • withProxy

        public Consul.Builder withProxy​(java.net.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​(java.util.concurrent.ExecutorService executorService)
        Sets the ExecutorService to be used by the internal tasks 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 tasks dispatcher.
        Returns:
      • 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 ConnetcionPool to be injected in the internal OkHttpClient
        Returns:
      • withClientConfiguration

        public Consul.Builder withClientConfiguration​(ClientConfig clientConfig)
        Sets the configuration for the clients. The configuration will fallback 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.