Interface PulsarClientBuilder


public interface PulsarClientBuilder
Builder for configuring and creating a PulsarClient.
  • Method Details

    • build

      Build and return the configured client.
      Returns:
      the configured PulsarClient instance
      Throws:
      PulsarClientException - if the client cannot be created (e.g., invalid configuration or connection failure)
    • serviceUrl

      PulsarClientBuilder serviceUrl(String serviceUrl)
      Set the Pulsar service URL — the broker's binary-protocol endpoint.

      Must use pulsar:// or pulsar+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 - if serviceUrl is null, blank, or does not use pulsar:// / pulsar+ssl://
    • authentication

      PulsarClientBuilder authentication(Authentication 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 plugin
      authParamsString - 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

      PulsarClientBuilder operationTimeout(Duration timeout)
      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

      PulsarClientBuilder connectionPolicy(ConnectionPolicy policy)
      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

      PulsarClientBuilder transactionPolicy(TransactionPolicy policy)
      Set the transaction policy.
      Parameters:
      policy - the transaction policy controlling transaction behavior and timeouts
      Returns:
      this builder instance for chaining
    • tlsPolicy

      PulsarClientBuilder tlsPolicy(TlsPolicy policy)
      Configure TLS for the client connection.
      Parameters:
      policy - the TLS policy to apply to broker connections
      Returns:
      this builder instance for chaining
      See Also:
      • invalid reference
        TlsPolicy#of(String)
      • invalid reference
        TlsPolicy#ofMutualTls(String, String, String)
      • TlsPolicy.ofInsecure()
    • openTelemetry

      PulsarClientBuilder openTelemetry(io.opentelemetry.api.OpenTelemetry openTelemetry)
      Provide a custom OpenTelemetry instance 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 MeterProvider and TracerProvider it contains. This means:

      • To keep metrics only (no tracing), configure the instance with a MeterProvider and leave the TracerProvider as no-op.
      • To enable distributed tracing, configure the instance with both a MeterProvider and a TracerProvider.
      • To disable all telemetry, pass OpenTelemetry.noop().
      Parameters:
      openTelemetry - the OpenTelemetry instance to use
      Returns:
      this builder instance for chaining
    • memoryLimit

      PulsarClientBuilder memoryLimit(MemorySize size)
      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

      PulsarClientBuilder listenerName(String name)
      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

      PulsarClientBuilder description(String 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