Package com.orbitz.consul
Class Consul.Builder
- java.lang.Object
-
- com.orbitz.consul.Consul.Builder
-
-
Method Summary
Modifier and Type Method Description Consulbuild()Constructs a newConsulclient.Consul.BuilderwithAclToken(java.lang.String token)Sets the ACL token to be used with ConsulConsul.BuilderwithBasicAuth(java.lang.String username, java.lang.String password)Sets the username and password to be used for basic authenticationConsul.BuilderwithClientConfiguration(ClientConfig clientConfig)Sets the configuration for the clients.Consul.BuilderwithClientEventCallback(ClientEventCallback callback)Sets the event callback for the clients.Consul.BuilderwithConnectionPool(okhttp3.ConnectionPool connectionPool)Sets the ConnectionPool to be used by OkHttp Client By default, an ConnectionPool is created internally.Consul.BuilderwithConnectTimeoutMillis(long timeoutMillis)Connect timeout for OkHttpClientConsul.BuilderwithConsulBookend(ConsulBookend consulBookend)Attaches aConsulBookendto each Consul request.Consul.BuilderwithExecutorService(java.util.concurrent.ExecutorService executorService)Sets the ExecutorService to be used by the internal tasks dispatcher.Consul.BuilderwithFailoverInterceptor(ConsulFailoverStrategy strategy)Constructs a failover interceptor with the givenConsulFailoverStrategy.Consul.BuilderwithHeaders(java.util.Map<java.lang.String,java.lang.String> headers)Sets headers to be included with each Consul request.Consul.BuilderwithHostAndPort(com.google.common.net.HostAndPort hostAndPort)Sets the URL from aHostAndPortobject.Consul.BuilderwithHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)Sets theHostnameVerifierfor the client.Consul.BuilderwithHttps(boolean withHttps)Use HTTPS connections for all requests.Consul.BuilderwithMultipleHostAndPort(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.Consul.BuilderwithPing(boolean ping)Instructs the builder that the AgentClient should attempt a ping before returning the Consul instanceConsul.BuilderwithProxy(java.net.Proxy proxy)Sets theProxyfor the client.Consul.BuilderwithReadTimeoutMillis(long timeoutMillis)Read timeout for OkHttpClientConsul.BuilderwithSslContext(javax.net.ssl.SSLContext sslContext)Sets theSSLContextfor the client.Consul.BuilderwithTokenAuth(java.lang.String token)Sets the token used for authenticationConsul.BuilderwithTrustManager(javax.net.ssl.X509TrustManager trustManager)Sets theX509TrustManagerfor the client.Consul.BuilderwithUrl(java.lang.String url)Sets the URL from a string.Consul.BuilderwithUrl(java.net.URL url)Sets the URL from aURLobject.Consul.BuilderwithWriteTimeoutMillis(long timeoutMillis)Write timeout for OkHttpClient
-
-
-
Method Detail
-
withUrl
public Consul.Builder withUrl(java.net.URL url)
Sets the URL from aURLobject.- 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 usernamepassword- 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 aConsulBookendto 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 aHostAndPortobject.- 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 nextHostAndPortspecified is used to retry the request. This will continue until all urls are exhuasted.- Parameters:
hostAndPort- A collection ofHostAndPortthat define the list of Consul agent addresses to use.blacklistTimeInMillis- The timeout (in milliseconds) to blacklist a particularHostAndPortbefore trying to use it again.- Returns:
- The builder.
-
withFailoverInterceptor
public Consul.Builder withFailoverInterceptor(ConsulFailoverStrategy strategy)
Constructs a failover interceptor with the givenConsulFailoverStrategy.- Parameters:
strategy- The strategy to use.- 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 theSSLContextfor the client.- Parameters:
sslContext- The SSL context for HTTPS agents.- Returns:
- The builder.
-
withTrustManager
public Consul.Builder withTrustManager(javax.net.ssl.X509TrustManager trustManager)
Sets theX509TrustManagerfor 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 theHostnameVerifierfor the client.- Parameters:
hostnameVerifier- The hostname verifier to use.- Returns:
- The builder.
-
withProxy
public Consul.Builder withProxy(java.net.Proxy proxy)
Sets theProxyfor 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 theConsul.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 theConsul.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
-
-