Package org.apache.pulsar.client.api.v5
Interface PulsarClientBuilder
public interface PulsarClientBuilder
Builder for configuring and creating a
PulsarClient.-
Method Summary
Modifier and TypeMethodDescriptionauthentication(String authPluginClassName, String authParamsString) Set authentication by plugin class name and parameter string.authentication(Authentication authentication) Set the authentication provider.build()Build and return the configured client.connectionPolicy(ConnectionPolicy policy) Configure connection-level settings such as timeouts, pool size, threading, keep-alive, and proxy configuration.description(String description) A human-readable description of this client (for logging and debugging).listenerName(String name) Set the listener name for multi-listener brokers.memoryLimit(MemorySize size) Maximum amount of direct memory the client can use for pending messages.openTelemetry(io.opentelemetry.api.OpenTelemetry openTelemetry) Provide a customOpenTelemetryinstance for metrics and tracing.operationTimeout(Duration timeout) Timeout for client operations (e.g., creating producers/consumers).serviceUrl(String serviceUrl) Set the Pulsar service URL — the broker's binary-protocol endpoint.Configure TLS for the client connection.transactionPolicy(TransactionPolicy policy) Set the transaction policy.
-
Method Details
-
build
Build and return the configured client.- Returns:
- the configured
PulsarClientinstance - Throws:
PulsarClientException- if the client cannot be created (e.g., invalid configuration or connection failure)
-
serviceUrl
Set the Pulsar service URL — the broker's binary-protocol endpoint.Must use
pulsar://orpulsar+ssl://. The admin/web service URL (http://.../https://...) is NOT accepted.- Parameters:
serviceUrl- the Pulsar broker service URL to connect to, e.g.pulsar://localhost:6650- Returns:
- this builder instance for chaining
- Throws:
IllegalArgumentException- ifserviceUrlis null, blank, or does not usepulsar:///pulsar+ssl://
-
authentication
Set the authentication provider.- Parameters:
authentication- the authentication provider to use for connecting to the broker- Returns:
- this builder instance for chaining
-
authentication
PulsarClientBuilder authentication(String authPluginClassName, String authParamsString) throws PulsarClientException Set authentication by plugin class name and parameter string.- Parameters:
authPluginClassName- the fully qualified class name of the authentication pluginauthParamsString- the authentication parameters as a serialized string- Returns:
- this builder instance for chaining
- Throws:
PulsarClientException- if the authentication plugin cannot be loaded or configured
-
operationTimeout
Timeout for client operations (e.g., creating producers/consumers).- Parameters:
timeout- the maximum duration to wait for an operation to complete- Returns:
- this builder instance for chaining
-
connectionPolicy
Configure connection-level settings such as timeouts, pool size, threading, keep-alive, and proxy configuration.- Parameters:
policy- the connection policy- Returns:
- this builder instance for chaining
- See Also:
-
transactionPolicy
Set the transaction policy.- Parameters:
policy- the transaction policy controlling transaction behavior and timeouts- Returns:
- this builder instance for chaining
-
tlsPolicy
Configure TLS for the client connection.- Parameters:
policy- the TLS policy to apply to broker connections- Returns:
- this builder instance for chaining
- See Also:
-
openTelemetry
Provide a customOpenTelemetryinstance for metrics and tracing.If not set, the client creates its own internal instance that exports metrics (via a Prometheus-compatible endpoint) with tracing disabled.
When a custom instance is provided, the client uses whatever
MeterProviderandTracerProviderit contains. This means:- To keep metrics only (no tracing), configure the instance with a
MeterProviderand leave theTracerProvideras no-op. - To enable distributed tracing, configure the instance with both a
MeterProviderand aTracerProvider. - To disable all telemetry, pass
OpenTelemetry.noop().
- Parameters:
openTelemetry- the OpenTelemetry instance to use- Returns:
- this builder instance for chaining
- To keep metrics only (no tracing), configure the instance with a
-
memoryLimit
Maximum amount of direct memory the client can use for pending messages.- Parameters:
size- the memory limit for pending messages across all producers- Returns:
- this builder instance for chaining
- See Also:
-
listenerName
Set the listener name for multi-listener brokers.- Parameters:
name- the listener name to use when connecting to brokers that advertise multiple listener endpoints- Returns:
- this builder instance for chaining
-
description
A human-readable description of this client (for logging and debugging).- Parameters:
description- a descriptive label for this client instance- Returns:
- this builder instance for chaining
-