Package org.apache.pulsar.client.api
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();
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds thePulsarClientSharedResourcesinstance.configureDnsResolver(Consumer<DnsResolverConfig> configurer) Configures the DNS resolver settings.configureEventLoop(Consumer<EventLoopGroupConfig> configurer) Configures the event loop group settings.configureThreadPool(PulsarClientSharedResources.SharedResource sharedResource, Consumer<ThreadPoolConfig<?>> configurer) Configures a thread pool for the specified shared resource type.configureTimer(Consumer<TimerConfig> configurer) Configures the timer settings.resourceTypes(Collection<PulsarClientSharedResources.SharedResource> sharedResource) resourceTypes(PulsarClientSharedResources.SharedResource... sharedResource) Optionally limits the shared resource types to be created and exposed by the resultingPulsarClientSharedResources.Share only the configured resources.
-
Method Details
-
resourceTypes
PulsarClientSharedResourcesBuilder resourceTypes(Collection<PulsarClientSharedResources.SharedResource> sharedResource) - Parameters:
sharedResource- one or more resource types to include- Returns:
- this builder
-
build
PulsarClientSharedResources build()Builds thePulsarClientSharedResourcesinstance. It is necessary to callPulsarClientSharedResources.close()on the instance to release resources. All clients must be closed before closing the shared resources.- Returns:
- the shared resources to be used in
ClientBuilder.sharedResources(PulsarClientSharedResources)
-
configureEventLoop
Configures the event loop group settings.- Parameters:
configurer- a consumer that configures the event loop group settings- Returns:
- this builder instance for method chaining
-
configureDnsResolver
Configures the DNS resolver settings.- Parameters:
configurer- a consumer that configures the DNS resolver settings- Returns:
- this builder instance for method chaining
-
configureTimer
Configures the timer settings.- Parameters:
configurer- a consumer that configures the timer settings- Returns:
- this builder instance for method chaining