Overview
TheClientBuilder interface is used to configure and construct a PulsarClient instance. It provides a fluent API for setting connection parameters, authentication, TLS configuration, threading, and various client behaviors.
Creating a ClientBuilder
Core Methods
build()
Construct the finalPulsarClient instance.
The new PulsarClient instance
clone()
Create a copy of the current client builder.loadConf()
Load the configuration from provided config map.Configuration map to load
Connection Configuration
serviceUrl()
Configure the service URL for the Pulsar service. This parameter is required.The URL of the Pulsar service that the client should connect to
pulsar://my-broker:6650for regular endpointpulsar+ssl://my-broker:6651for TLS encrypted endpoint
serviceUrlProvider()
Configure the service URL provider for Pulsar service.The provider instance that dynamically provides a service URL
listenerName()
Configure the listenerName that the broker will return the corresponding advertisedListener.The listener name
connectionMaxIdleSeconds()
Release the connection if it is not used for more than specified seconds. Defaults to 25 seconds.Maximum idle time in seconds
connectionTimeout()
Set the duration of time to wait for a connection to a broker to be established.The duration to wait
The time unit in which the duration is defined
connectionsPerBroker()
Sets the max number of connections that the client library will open to a single broker.Max number of connections per broker (needs to be greater than or equal to 0)
Authentication
authentication(Authentication)
Set the authentication provider to use in the Pulsar client instance.An instance of the Authentication provider already constructed
authentication(String, String)
Configure the authentication provider to use in the Pulsar client instance.Name of the Authentication-Plugin you want to use
String which represents parameters for the Authentication-Plugin, e.g., “key1:val1,key2:val2”
authentication(String, Map)
Configure the authentication provider using a config map.Name of the Authentication-Plugin you want to use
Map which represents parameters for the Authentication-Plugin
TLS Configuration
enableTls()
Configure whether to use TLS encryption on the connection.Deprecated: use “pulsar+ssl://” in serviceUrl to enable TLS instead.
tlsKeyFilePath()
Set the path to the TLS key file.Path to the TLS key file
tlsCertificateFilePath()
Set the path to the TLS certificate file.Path to the TLS certificate file
tlsTrustCertsFilePath()
Set the path to the trusted TLS certificate file.Path to the trusted TLS certificate file
allowTlsInsecureConnection()
Configure whether the Pulsar client accepts untrusted TLS certificate from broker. Default is false.Whether to accept an untrusted TLS certificate
enableTlsHostnameVerification()
It allows to validate hostname verification when client connects to broker over TLS.Whether to enable TLS hostname verification
useKeyStoreTls()
If TLS is enabled, whether use KeyStore type as TLS configuration parameter. False means use default pem type configuration.Whether to use KeyStore type
sslProvider()
The name of the security provider used for SSL connections. Default value is the default security provider of the JVM.The SSL provider name
tlsKeyStoreType()
The file format of the key store file.The key store type
tlsKeyStorePath()
The location of the key store file.The key store path
tlsKeyStorePassword()
The store password for the key store file.The key store password
tlsTrustStoreType()
The file format of the trust store file.The trust store type
tlsTrustStorePath()
The location of the trust store file.The trust store path
tlsTrustStorePassword()
The store password for the trust store file.The trust store password
tlsCiphers()
A list of cipher suites.The cipher suites to use
tlsProtocols()
The SSL protocol used to generate the SSLContext. Default setting is TLS.Allowed values in recent JVMs are TLS, TLSv1.3, TLSv1.2 and TLSv1.1
Threading Configuration
ioThreads()
Set the number of threads to be used for handling connections to brokers. Default isRuntime.getRuntime().availableProcessors().
The number of IO threads
listenerThreads()
Set the number of threads to be used for message listeners. Default isRuntime.getRuntime().availableProcessors().
The number of listener threads
Timeout Configuration
operationTimeout()
Set the operation timeout. Default is 30 seconds.Operation timeout
Time unit for operationTimeout
lookupTimeout()
Set lookup timeout. Default matches operation timeout.Lookup timeout
Time unit for lookupTimeout
Network Configuration
enableTcpNoDelay()
Configure whether to use TCP no-delay flag on the connection. Default value is true.Whether to enable TCP no-delay feature
keepAliveInterval()
Set keep alive interval for each client-broker-connection. Default is 30 seconds.Keep alive interval
The time unit in which the keepAliveInterval is defined
Memory and Resource Configuration
memoryLimit()
Configure a limit on the amount of direct memory that will be allocated by this client instance. Default is 64 MB.The limit (setting to 0 will disable the limit)
The memory limit size unit
maxConcurrentLookupRequests()
Number of concurrent lookup-requests allowed to send on each broker-connection to prevent overload on broker. Default is 5000.Max concurrent lookup requests
maxLookupRequests()
Number of max lookup-requests allowed on each broker-connection to prevent overload on broker. Default is 50000.Max lookup requests
maxLookupRedirects()
Set the maximum number of times a lookup-request to a broker will be redirected.The maximum number of redirects
maxNumberOfRejectedRequestPerConnection()
Set max number of broker-rejected requests in a certain time-frame (60 seconds). Default is 50.Max number of rejected requests
Backoff Configuration
startingBackoffInterval()
Set the duration of time for a backoff interval.The duration of the interval
The time unit in which the duration is defined
maxBackoffInterval()
Set the maximum duration of time for a backoff interval.The duration of the interval
The time unit in which the duration is defined
Telemetry and Monitoring
openTelemetry()
Configure OpenTelemetry for Pulsar Client.The OpenTelemetry instance
enableTracing()
Enable OpenTelemetry distributed tracing.Whether to enable tracing (default: false)
statsInterval()
Set the interval between each stat info. Default is 60 seconds.The interval between each stat info
Time unit for statsInterval
Deprecated: See openTelemetry() instead.
Advanced Configuration
clock()
The clock used by the pulsar client.The clock used by the pulsar client to retrieve time information
enableBusyWait()
Option to enable busy-wait settings. Default is false.Whether to enable busy wait
proxyServiceUrl()
Proxy-service url when client would like to connect to broker via proxy.Proxy service url
Protocol to decide type of proxy routing eg: SNI-routing
enableTransaction()
If enable transaction, start the transactionCoordinatorClient with pulsar client.Whether enable transaction feature
dnsLookupBind()
Set dns lookup bind address and port.DNS bind address
DNS bind port
dnsServerAddresses()
Set dns lookup server addresses.DNS server addresses
socks5ProxyAddress()
Set socks5 proxy address.SOCKS5 proxy address
socks5ProxyUsername()
Set socks5 proxy username.SOCKS5 proxy username
socks5ProxyPassword()
Set socks5 proxy password.SOCKS5 proxy password
description()
Set the description.The description of the current PulsarClient instance
Pulsar-Java-v<x.y.z> will be carried and saved by the broker. This method provides a way to add more description to a specific PulsarClient instance.
sharedResources()
Provide a set of shared client resources to be reused by this client.The shared resources instance created with PulsarClientSharedResources.builder()
lookupProperties()
Set the properties used for topic lookup.Lookup properties map
serviceUrlQuarantineInitDuration()
Configure the service URL init quarantine duration. Default is 60 seconds.The initial quarantine duration for unavailable endpoint
The time unit for the quarantine duration
serviceUrlQuarantineMaxDuration()
Configure the service URL max quarantine duration. Default is 1 day.The maximum quarantine duration for unavailable endpoint
The time unit for the quarantine duration
sslFactoryPlugin()
Set the SSL Factory Plugin for custom implementation to create SSL Context and SSLEngine.SSL factory class name
sslFactoryPluginParams()
Set the SSL Factory Plugin params for the ssl factory plugin to use.Params in String format that will be inputted to the SSL Factory Plugin
autoCertRefreshSeconds()
Set Cert Refresh interval in seconds.Auto certificate refresh interval in seconds