public interface ClientBuilder extends Cloneable
PulsarClient
instance.Modifier and Type | Method and Description |
---|---|
ClientBuilder |
allowTlsInsecureConnection(boolean allowTlsInsecureConnection)
Configure whether the Pulsar client accept untrusted TLS certificate from broker (default: false)
|
ClientBuilder |
authentication(Authentication authentication)
Set the authentication provider to use in the Pulsar client instance.
|
ClientBuilder |
authentication(String authPluginClassName,
Map<String,String> authParams)
Set the authentication provider to use in the Pulsar client instance.
|
ClientBuilder |
authentication(String authPluginClassName,
String authParamsString)
Set the authentication provider to use in the Pulsar client instance.
|
PulsarClient |
build() |
ClientBuilder |
clone()
Create a copy of the current client builder.
|
ClientBuilder |
connectionsPerBroker(int connectionsPerBroker)
Sets the max number of connection that the client library will open to a single broker.
|
ClientBuilder |
enableTcpNoDelay(boolean enableTcpNoDelay)
Configure whether to use TCP no-delay flag on the connection, to disable Nagle algorithm.
|
ClientBuilder |
enableTls(boolean enableTls)
Deprecated.
use "pulsar+ssl://" in serviceUrl to enable
|
ClientBuilder |
enableTlsHostnameVerification(boolean enableTlsHostnameVerification)
It allows to validate hostname verification when client connects to broker over tls.
|
ClientBuilder |
ioThreads(int numIoThreads)
Set the number of threads to be used for handling connections to brokers (default: 1 thread)
|
ClientBuilder |
keepAliveInterval(int keepAliveIntervalSeconds,
TimeUnit unit)
Set keep alive interval in seconds for each client-broker-connection.
|
ClientBuilder |
listenerThreads(int numListenerThreads)
Set the number of threads to be used for message listeners (default: 1 thread)
|
ClientBuilder |
loadConf(Map<String,Object> config)
Load the configuration from provided config map.
|
ClientBuilder |
maxConcurrentLookupRequests(int maxConcurrentLookupRequests)
Number of concurrent lookup-requests allowed to send on each broker-connection to prevent overload on broker.
|
ClientBuilder |
maxLookupRequests(int maxLookupRequests)
Number of max lookup-requests allowed on each broker-connection to prevent overload on broker.
|
ClientBuilder |
maxNumberOfRejectedRequestPerConnection(int maxNumberOfRejectedRequestPerConnection)
Set max number of broker-rejected requests in a certain time-frame (30 seconds) after which current connection
will be closed and client creates a new connection that give chance to connect a different broker (default:
50)
|
ClientBuilder |
operationTimeout(int operationTimeout,
TimeUnit unit)
Set the operation timeout (default: 30 seconds)
|
ClientBuilder |
serviceUrl(String serviceUrl)
Configure the service URL for the Pulsar service.
|
ClientBuilder |
serviceUrlProvider(ServiceUrlProvider serviceUrlProvider)
Configure the service URL provider for Pulsar service
|
ClientBuilder |
statsInterval(long statsInterval,
TimeUnit unit)
Set the interval between each stat info (default: 60 seconds) Stats will be activated with positive
statsIntervalSeconds It should be set to at least 1 second
|
ClientBuilder |
tlsTrustCertsFilePath(String tlsTrustCertsFilePath)
Set the path to the trusted TLS certificate file
|
PulsarClient build() throws PulsarClientException
PulsarClient
instancePulsarClientException
ClientBuilder loadConf(Map<String,Object> config)
Example:
Map<String, Object> config = new HashMap<>(); config.put("serviceUrl", "pulsar://localhost:5550"); config.put("numIoThreads", 20); ClientBuilder builder = ...; builder = builder.loadConf(config); PulsarClient client = builder.build();
config
- configuration to loadClientBuilder clone()
Cloning the builder can be used to share an incomplete configuration and specialize it multiple times. For example:
ClientBuilder builder = PulsarClient.builder().ioThreads(8).listenerThreads(4); PulsarClient client1 = builder.clone().serviceUrl(URL_1).build(); PulsarClient client2 = builder.clone().serviceUrl(URL_2).build();
ClientBuilder serviceUrl(String serviceUrl)
This parameter is required
serviceUrl
- ClientBuilder serviceUrlProvider(ServiceUrlProvider serviceUrlProvider)
serviceUrlProvider
- ClientBuilder authentication(Authentication authentication)
Example:
String AUTH_CLASS = "org.apache.pulsar.client.impl.auth.AuthenticationTls";
Map conf = new TreeMap<>();
conf.put("tlsCertFile", "/my/cert/file");
conf.put("tlsKeyFile", "/my/key/file");
Authentication auth = AuthenticationFactor.create(AUTH_CLASS, conf);
PulsarClient client = PulsarClient.builder()
.serviceUrl(SERVICE_URL)
.authentication(auth)
.build();
....
authentication
- an instance of the Authentication
provider already constructedClientBuilder authentication(String authPluginClassName, String authParamsString) throws PulsarClientException.UnsupportedAuthenticationException
Example:
String AUTH_CLASS = "org.apache.pulsar.client.impl.auth.AuthenticationTls";
String AUTH_PARAMS = "tlsCertFile:/my/cert/file,tlsKeyFile:/my/key/file";
PulsarClient client = PulsarClient.builder()
.serviceUrl(SERVICE_URL)
.authentication(AUTH_CLASS, AUTH_PARAMS)
.build();
....
authPluginClassName
- name of the Authentication-Plugin you want to useauthParamsString
- string which represents parameters for the Authentication-Plugin, e.g., "key1:val1,key2:val2"PulsarClientException.UnsupportedAuthenticationException
- failed to instantiate specified Authentication-PluginClientBuilder authentication(String authPluginClassName, Map<String,String> authParams) throws PulsarClientException.UnsupportedAuthenticationException
Example:
String AUTH_CLASS = "org.apache.pulsar.client.impl.auth.AuthenticationTls";
Map conf = new TreeMap<>();
conf.put("tlsCertFile", "/my/cert/file");
conf.put("tlsKeyFile", "/my/key/file");
PulsarClient client = PulsarClient.builder()
.serviceUrl(SERVICE_URL)
.authentication(AUTH_CLASS, conf)
.build();
....
authPluginClassName
- name of the Authentication-Plugin you want to useauthParams
- map which represents parameters for the Authentication-PluginPulsarClientException.UnsupportedAuthenticationException
- failed to instantiate specified Authentication-PluginClientBuilder operationTimeout(int operationTimeout, TimeUnit unit)
Producer-create, subscribe and unsubscribe operations will be retried until this interval, after which the operation will be marked as failed
operationTimeout
- operation timeoutunit
- time unit for operationTimeout
ClientBuilder ioThreads(int numIoThreads)
numIoThreads
- ClientBuilder listenerThreads(int numListenerThreads)
numListenerThreads
- ClientBuilder connectionsPerBroker(int connectionsPerBroker)
By default, the connection pool will use a single connection for all the producers and consumers. Increasing this parameter may improve throughput when using many producers over a high latency connection.
connectionsPerBroker
- max number of connections per broker (needs to be greater than 0)ClientBuilder enableTcpNoDelay(boolean enableTcpNoDelay)
No-delay features make sure packets are sent out on the network as soon as possible, and it's critical to achieve
low latency publishes. On the other hand, sending out a huge number of small packets might limit the overall
throughput, so if latency is not a concern, it's advisable to set the useTcpNoDelay
flag to false.
Default value is true
enableTcpNoDelay
- @Deprecated ClientBuilder enableTls(boolean enableTls)
enableTls
- ClientBuilder tlsTrustCertsFilePath(String tlsTrustCertsFilePath)
tlsTrustCertsFilePath
- ClientBuilder allowTlsInsecureConnection(boolean allowTlsInsecureConnection)
allowTlsInsecureConnection
- ClientBuilder enableTlsHostnameVerification(boolean enableTlsHostnameVerification)
enableTlsHostnameVerification
- ClientBuilder statsInterval(long statsInterval, TimeUnit unit)
statsIntervalSeconds
- the interval between each stat infounit
- time unit for statsInterval
ClientBuilder maxConcurrentLookupRequests(int maxConcurrentLookupRequests)
PulsarClient
maxConcurrentLookupRequests
- ClientBuilder maxLookupRequests(int maxLookupRequests)
maxLookupRequests
- ClientBuilder maxNumberOfRejectedRequestPerConnection(int maxNumberOfRejectedRequestPerConnection)
maxNumberOfRejectedRequestPerConnection
- ClientBuilder keepAliveInterval(int keepAliveIntervalSeconds, TimeUnit unit)
keepAliveIntervalSeconds
- unit
- time unit for statsInterval
Copyright © 2017–2018 Apache Software Foundation. All rights reserved.