Package com.orbitz.consul
Class Consul.Builder
- java.lang.Object
-
- com.orbitz.consul.Consul.Builder
-
-
Method Summary
Modifier and Type Method Description Consul
build()
Constructs a newConsul
client.Consul.Builder
withAclToken(java.lang.String token)
Sets the ACL token to be used with ConsulConsul.Builder
withBasicAuth(java.lang.String username, java.lang.String password)
Sets the username and password to be used for basic authenticationConsul.Builder
withClientConfiguration(ClientConfig clientConfig)
Sets the configuration for the clients.Consul.Builder
withClientEventCallback(ClientEventCallback callback)
Sets the event callback for the clients.Consul.Builder
withConnectionPool(okhttp3.ConnectionPool connectionPool)
Sets the ConnectionPool to be used by OkHttp Client By default, an ConnectionPool is created internally.Consul.Builder
withConnectTimeoutMillis(long timeoutMillis)
Connect timeout for OkHttpClientConsul.Builder
withConsulBookend(ConsulBookend consulBookend)
Attaches aConsulBookend
to each Consul request.Consul.Builder
withExecutorService(java.util.concurrent.ExecutorService executorService)
Sets the ExecutorService to be used by the internal tasks dispatcher.Consul.Builder
withFailoverInterceptor(ConsulFailoverStrategy strategy)
Constructs a failover interceptor with the givenConsulFailoverStrategy
.Consul.Builder
withHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Sets headers to be included with each Consul request.Consul.Builder
withHostAndPort(com.google.common.net.HostAndPort hostAndPort)
Sets the URL from aHostAndPort
object.Consul.Builder
withHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
Sets theHostnameVerifier
for the client.Consul.Builder
withHttps(boolean withHttps)
Use HTTPS connections for all requests.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.Consul.Builder
withPing(boolean ping)
Instructs the builder that the AgentClient should attempt a ping before returning the Consul instanceConsul.Builder
withProxy(java.net.Proxy proxy)
Sets theProxy
for the client.Consul.Builder
withReadTimeoutMillis(long timeoutMillis)
Read timeout for OkHttpClientConsul.Builder
withSslContext(javax.net.ssl.SSLContext sslContext)
Sets theSSLContext
for the client.Consul.Builder
withTokenAuth(java.lang.String token)
Sets the token used for authenticationConsul.Builder
withTrustManager(javax.net.ssl.X509TrustManager trustManager)
Sets theX509TrustManager
for the client.Consul.Builder
withUrl(java.lang.String url)
Sets the URL from a string.Consul.Builder
withUrl(java.net.URL url)
Sets the URL from aURL
object.Consul.Builder
withWriteTimeoutMillis(long timeoutMillis)
Write timeout for OkHttpClient
-
-
-
Method Detail
-
withUrl
public Consul.Builder withUrl(java.net.URL url)
Sets the URL from aURL
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 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 aConsulBookend
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 aHostAndPort
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 nextHostAndPort
specified is used to retry the request. This will continue until all urls are exhuasted.- Parameters:
hostAndPort
- A collection ofHostAndPort
that define the list of Consul agent addresses to use.blacklistTimeInMillis
- The timeout (in milliseconds) to blacklist a particularHostAndPort
before 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 theSSLContext
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 theX509TrustManager
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 theHostnameVerifier
for the client.- Parameters:
hostnameVerifier
- The hostname verifier to use.- Returns:
- The builder.
-
withProxy
public Consul.Builder withProxy(java.net.Proxy proxy)
Sets theProxy
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 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
-
-