public class ClientBuilderImpl extends Object implements ClientBuilder
| Constructor and Description |
|---|
ClientBuilderImpl() |
ClientBuilderImpl(ClientConfigurationData conf) |
| Modifier and Type | Method and Description |
|---|---|
ClientBuilder |
allowTlsInsecureConnection(boolean tlsAllowInsecureConnection)
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 useTcpNoDelay)
Configure whether to use TCP no-delay flag on the connection, to disable Nagle algorithm.
|
ClientBuilder |
enableTls(boolean useTls)
Configure whether to use TLS encryption on the connection
(default: true if serviceUrl starts with "pulsar+ssl://", false otherwise)
|
ClientBuilder |
enableTlsHostnameVerification(boolean enableTlsHostnameVerification)
It allows to validate hostname verification when client connects to broker over tls.
|
ClientConfigurationData |
getClientConfigurationData() |
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 concurrentLookupRequests)
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
|
public ClientBuilderImpl()
public ClientBuilderImpl(ClientConfigurationData conf)
public PulsarClient build() throws PulsarClientException
build in interface ClientBuilderPulsarClient instancePulsarClientExceptionpublic ClientBuilder clone()
ClientBuilderCloning 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();
clone in interface ClientBuilderclone in class Objectpublic ClientBuilder loadConf(Map<String,Object> config)
ClientBuilderExample:
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();
loadConf in interface ClientBuilderconfig - configuration to loadpublic ClientBuilder serviceUrl(String serviceUrl)
ClientBuilderThis parameter is required
serviceUrl in interface ClientBuilderpublic ClientBuilder serviceUrlProvider(ServiceUrlProvider serviceUrlProvider)
ClientBuilderserviceUrlProvider in interface ClientBuilderpublic ClientBuilder authentication(Authentication authentication)
ClientBuilderExample:
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 in interface ClientBuilderauthentication - an instance of the Authentication provider already constructedpublic ClientBuilder authentication(String authPluginClassName, String authParamsString) throws PulsarClientException.UnsupportedAuthenticationException
ClientBuilderExample:
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();
....
authentication in interface ClientBuilderauthPluginClassName - 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-Pluginpublic ClientBuilder authentication(String authPluginClassName, Map<String,String> authParams) throws PulsarClientException.UnsupportedAuthenticationException
ClientBuilderExample:
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();
....
authentication in interface ClientBuilderauthPluginClassName - name of the Authentication-Plugin you want to useauthParams - map which represents parameters for the Authentication-PluginPulsarClientException.UnsupportedAuthenticationException - failed to instantiate specified Authentication-Pluginpublic ClientBuilder operationTimeout(int operationTimeout, TimeUnit unit)
ClientBuilderProducer-create, subscribe and unsubscribe operations will be retried until this interval, after which the operation will be marked as failed
operationTimeout in interface ClientBuilderoperationTimeout - operation timeoutunit - time unit for operationTimeoutpublic ClientBuilder ioThreads(int numIoThreads)
ClientBuilderioThreads in interface ClientBuilderpublic ClientBuilder listenerThreads(int numListenerThreads)
ClientBuilderlistenerThreads in interface ClientBuilderpublic ClientBuilder connectionsPerBroker(int connectionsPerBroker)
ClientBuilderBy 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 in interface ClientBuilderconnectionsPerBroker - max number of connections per broker (needs to be greater than 0)public ClientBuilder enableTcpNoDelay(boolean useTcpNoDelay)
ClientBuilder
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 in interface ClientBuilderpublic ClientBuilder enableTls(boolean useTls)
ClientBuilderenableTls in interface ClientBuilderpublic ClientBuilder enableTlsHostnameVerification(boolean enableTlsHostnameVerification)
ClientBuilderenableTlsHostnameVerification in interface ClientBuilderpublic ClientBuilder tlsTrustCertsFilePath(String tlsTrustCertsFilePath)
ClientBuildertlsTrustCertsFilePath in interface ClientBuilderpublic ClientBuilder allowTlsInsecureConnection(boolean tlsAllowInsecureConnection)
ClientBuilderallowTlsInsecureConnection in interface ClientBuilderpublic ClientBuilder statsInterval(long statsInterval, TimeUnit unit)
ClientBuilderstatsInterval in interface ClientBuilderunit - time unit for statsIntervalpublic ClientBuilder maxConcurrentLookupRequests(int concurrentLookupRequests)
ClientBuilderPulsarClientmaxConcurrentLookupRequests in interface ClientBuilderpublic ClientBuilder maxLookupRequests(int maxLookupRequests)
ClientBuildermaxLookupRequests in interface ClientBuilderpublic ClientBuilder maxNumberOfRejectedRequestPerConnection(int maxNumberOfRejectedRequestPerConnection)
ClientBuildermaxNumberOfRejectedRequestPerConnection in interface ClientBuilderpublic ClientBuilder keepAliveInterval(int keepAliveIntervalSeconds, TimeUnit unit)
ClientBuilderkeepAliveInterval in interface ClientBuilderunit - time unit for statsIntervalpublic ClientConfigurationData getClientConfigurationData()
Copyright © 2017–2018 Apache Software Foundation. All rights reserved.