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)
Configure the authentication provider to use in the Pulsar client instance
using a config map.
|
ClientBuilder |
authentication(String authPluginClassName,
String authParamsString)
Configure the authentication provider to use in the Pulsar client instance.
|
PulsarClient |
build()
Construct the final
PulsarClient instance |
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 |
connectionTimeout(int duration,
TimeUnit unit)
Set the duration of time to wait for a connection to a broker to be established.
|
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
instancePulsarClient
instancePulsarClientException
ClientBuilder loadConf(Map<String,Object> config)
Example:
Map<String, Object> config = new HashMap<>();
config.put("serviceUrl", "pulsar://localhost:6650");
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("pulsar://localhost:6650").build();
PulsarClient client2 = builder.clone()
.serviceUrl("pulsar://other-host:6650").build();
ClientBuilder serviceUrl(String serviceUrl)
This parameter is required.
Examples:
pulsar://my-broker:6650
for regular endpointpulsar+ssl://my-broker:6651
for TLS encrypted endpointserviceUrl
- the URL of the Pulsar service that the client should connect toClientBuilder serviceUrlProvider(ServiceUrlProvider serviceUrlProvider)
Instead of specifying a static service URL string (with serviceUrl(String)
), an application can pass a
ServiceUrlProvider
instance that dynamically provide a service URL.
serviceUrlProvider
- the provider instanceClientBuilder authentication(Authentication authentication)
Example:
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar+ssl://broker.example.com:6651/")
.authentication(
AuthenticationFactory.TLS("/my/cert/file", "/my/key/file")
.build();
For token based authentication, this will look like:
AuthenticationFactory.token("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJKb2UifQ.ipevRNuRP6HflG8cFKnmUPtypruRC4fb1DWtoLL62SY")
authentication
- an instance of the Authentication
provider already constructedClientBuilder authentication(String authPluginClassName, String authParamsString) throws PulsarClientException.UnsupportedAuthenticationException
Example:
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar+ssl://broker.example.com:6651/)
.authentication(
"org.apache.pulsar.client.impl.auth.AuthenticationTls",
"tlsCertFile:/my/cert/file,tlsKeyFile:/my/key/file")
.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:
Map<String, String> conf = new TreeMap<>();
conf.put("tlsCertFile", "/my/cert/file");
conf.put("tlsKeyFile", "/my/key/file");
PulsarClient client = PulsarClient.builder()
.serviceUrl("pulsar+ssl://broker.example.com:6651/)
.authentication(
"org.apache.pulsar.client.impl.auth.AuthenticationTls", 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
- the number of IO threadsClientBuilder listenerThreads(int numListenerThreads)
The listener thread pool is shared across all the consumers and readers that are using a "listener" model to get messages. For a given consumer, the listener will be always invoked from the same thread, to ensure ordering.
numListenerThreads
- the number of listener threadsClientBuilder 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
- whether to enable TCP no-delay feature@Deprecated ClientBuilder enableTls(boolean enableTls)
enableTls
- ClientBuilder tlsTrustCertsFilePath(String tlsTrustCertsFilePath)
tlsTrustCertsFilePath
- ClientBuilder allowTlsInsecureConnection(boolean allowTlsInsecureConnection)
allowTlsInsecureConnection
- whether to accept a untrusted TLS certificateClientBuilder enableTlsHostnameVerification(boolean enableTlsHostnameVerification)
enableTlsHostnameVerification
- whether to enable TLS hostname verificationClientBuilder 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
ClientBuilder connectionTimeout(int duration, TimeUnit unit)
duration
- the duration to waitunit
- the time unit in which the duration is definedCopyright © 2017–2019 Apache Software Foundation. All rights reserved.