Interface PulsarClientSharedResourcesBuilder


public interface PulsarClientSharedResourcesBuilder
Builder for configuring and creating PulsarClientSharedResources.

Shared resources allow multiple PulsarClient instances to reuse common components (for example executors, timers, DNS resolver, event loop, connection pool), reducing memory footprint and thread count when many clients are created in the same JVM. This allows creating a large number of PulsarClient instances in a single JVM without wasting resources. Sharing the DNS resolver and cache will help reduce the number of DNS lookups performed by the clients and improve latency and reduce load on the DNS servers.

Typical usage:


 PulsarClientSharedResources shared = PulsarClientSharedResources
     .builder()
     // shared resources can be configured using a ClientBuilder
     .configureResources(PulsarClient.builder().ioThreads(4))
     .build();

 PulsarClient client = PulsarClient.builder()
     .sharedResources(shared)
     .serviceUrl("pulsar://localhost:6650")
     .build();

 client.close();
 // it's necessary to close the shared resources after usage
 shared.close();