@InterfaceAudience.Public @InterfaceStability.Stable public interface ClientBuilder extends Serializable, 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 |
clock(Clock clock)
The clock used by the pulsar client.
|
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 |
enableBusyWait(boolean enableBusyWait)
Option to enable busy-wait settings.
|
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 |
enableTransaction(boolean enableTransaction)
If enable transaction, start the transactionCoordinatorClient with pulsar client.
|
ClientBuilder |
ioThreads(int numIoThreads)
Set the number of threads to be used for handling connections to brokers (default: 1 thread).
|
ClientBuilder |
keepAliveInterval(int keepAliveInterval,
TimeUnit unit)
Set keep alive interval for each client-broker-connection.
|
ClientBuilder |
listenerName(String name)
Configure the listenerName that the broker will return the corresponding `advertisedListener`.
|
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 |
lookupTimeout(int lookupTimeout,
TimeUnit unit)
Set lookup timeout (default: matches operation timeout)
Lookup operations have a different load pattern to other operations.
|
ClientBuilder |
maxBackoffInterval(long duration,
TimeUnit unit)
Set the maximum duration of time for a backoff interval.
|
ClientBuilder |
maxConcurrentLookupRequests(int maxConcurrentLookupRequests)
Number of concurrent lookup-requests allowed to send on each broker-connection to prevent overload on broker.
|
ClientBuilder |
maxLookupRedirects(int maxLookupRedirects)
Set the maximum number of times a lookup-request to a broker will be redirected.
|
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 |
memoryLimit(long memoryLimit,
SizeUnit unit)
Configure a limit on the amount of direct memory that will be allocated by this client instance.
|
ClientBuilder |
operationTimeout(int operationTimeout,
TimeUnit unit)
Set the operation timeout (default: 30 seconds).
|
ClientBuilder |
proxyServiceUrl(String proxyServiceUrl,
ProxyProtocol proxyProtocol)
Proxy-service url when client would like to connect to broker via proxy.
|
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 |
socks5ProxyAddress(InetSocketAddress socks5ProxyAddress)
Set socks5 proxy address.
|
ClientBuilder |
socks5ProxyPassword(String socks5ProxyPassword)
Set socks5 proxy password.
|
ClientBuilder |
socks5ProxyUsername(String socks5ProxyUsername)
Set socks5 proxy username.
|
ClientBuilder |
sslProvider(String sslProvider)
The name of the security provider used for SSL connections.
|
ClientBuilder |
startingBackoffInterval(long duration,
TimeUnit unit)
Set the duration of time for a backoff interval.
|
ClientBuilder |
statsInterval(long statsInterval,
TimeUnit unit)
Set the interval between each stat info (default: 60 seconds) Stats will be activated with positive
statsInterval It should be set to at least 1 second.
|
ClientBuilder |
tlsCiphers(Set<String> tlsCiphers)
A list of cipher suites.
|
ClientBuilder |
tlsProtocols(Set<String> tlsProtocols)
The SSL protocol used to generate the SSLContext.
|
ClientBuilder |
tlsTrustCertsFilePath(String tlsTrustCertsFilePath)
Set the path to the trusted TLS certificate file.
|
ClientBuilder |
tlsTrustStorePassword(String tlsTrustStorePassword)
The store password for the key store file.
|
ClientBuilder |
tlsTrustStorePath(String tlsTrustStorePath)
The location of the trust store file.
|
ClientBuilder |
tlsTrustStoreType(String tlsTrustStoreType)
The file format of the trust store file.
|
ClientBuilder |
useKeyStoreTls(boolean useKeyStoreTls)
If Tls is enabled, whether use KeyStore type as tls configuration parameter.
|
PulsarClient build() throws PulsarClientException
PulsarClient
instance.PulsarClient
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 listenerName(String name)
name
- the listener nameClientBuilder 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 lookupTimeout(int lookupTimeout, TimeUnit unit)
lookupTimeout
- lookup timeoutunit
- time unit for lookupTimeout
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 or equal to 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 useKeyStoreTls(boolean useKeyStoreTls)
useKeyStoreTls
- ClientBuilder sslProvider(String sslProvider)
sslProvider
- ClientBuilder tlsTrustStoreType(String tlsTrustStoreType)
tlsTrustStoreType
- ClientBuilder tlsTrustStorePath(String tlsTrustStorePath)
tlsTrustStorePath
- ClientBuilder tlsTrustStorePassword(String tlsTrustStorePassword)
tlsTrustStorePassword
- ClientBuilder tlsCiphers(Set<String> tlsCiphers)
tlsCiphers
- ClientBuilder tlsProtocols(Set<String> tlsProtocols)
tlsProtocols
- ClientBuilder memoryLimit(long memoryLimit, SizeUnit unit)
Note: at this moment this is only limiting the memory for producers.
Setting this to 0 will disable the limit.
memoryLimit
- the limitunit
- the memory limit size unitClientBuilder statsInterval(long statsInterval, TimeUnit unit)
statsInterval
- the interval between each stat infounit
- time unit for statsInterval
ClientBuilder maxConcurrentLookupRequests(int maxConcurrentLookupRequests)
PulsarClient
.maxConcurrentLookupRequests
- ClientBuilder maxLookupRequests(int maxLookupRequests)
maxLookupRequests
- ClientBuilder maxLookupRedirects(int maxLookupRedirects)
maxLookupRedirects
- the maximum number of redirectsClientBuilder maxNumberOfRejectedRequestPerConnection(int maxNumberOfRejectedRequestPerConnection)
maxNumberOfRejectedRequestPerConnection
- ClientBuilder keepAliveInterval(int keepAliveInterval, TimeUnit unit)
keepAliveInterval
- unit
- the time unit in which the keepAliveInterval is definedClientBuilder connectionTimeout(int duration, TimeUnit unit)
duration
- the duration to waitunit
- the time unit in which the duration is definedClientBuilder startingBackoffInterval(long duration, TimeUnit unit)
duration
- the duration of the intervalunit
- the time unit in which the duration is definedClientBuilder maxBackoffInterval(long duration, TimeUnit unit)
duration
- the duration of the intervalunit
- the time unit in which the duration is definedClientBuilder enableBusyWait(boolean enableBusyWait)
enableBusyWait
- whether to enable busy waitClientBuilder clock(Clock clock)
The clock is currently used by producer for setting publish timestamps.
Clock.millis()
is called to retrieve current timestamp as the publish
timestamp when producers produce messages. The default clock is a system default zone
clock. So the publish timestamp is same as calling System.currentTimeMillis()
.
Warning: the clock is used for TTL enforcement and timestamp based seeks. so be aware of the impacts if you are going to use a different clock.
clock
- the clock used by the pulsar client to retrieve time informationClientBuilder proxyServiceUrl(String proxyServiceUrl, ProxyProtocol proxyProtocol)
ProxyProtocol
.proxyServiceUrl
- proxy service urlproxyProtocol
- protocol to decide type of proxy routing eg: SNI-routingClientBuilder enableTransaction(boolean enableTransaction)
enableTransaction
- whether enable transaction featureClientBuilder socks5ProxyAddress(InetSocketAddress socks5ProxyAddress)
socks5ProxyAddress
- ClientBuilder socks5ProxyUsername(String socks5ProxyUsername)
socks5ProxyUsername
- ClientBuilder socks5ProxyPassword(String socks5ProxyPassword)
socks5ProxyPassword
- Copyright © 2017–2021 Apache Software Foundation. All rights reserved.