Skip to content

[feat] Authentication implementations such as AuthenticationOAuth2 should support sharing thread pools or DNS cache #24795

@lhotari

Description

@lhotari

Search before reporting

  • I searched in the issues and found nothing similar.

Motivation

PIP-234 implementation #24790 adds support for sharing thread pools and DNS resolver/cache across multiple client instances. However, authentication implementations such as AuthenticationOAuth2 create new thread pools and DNS resolvers/caches. This isn't desired, since it would be useful to be able to share the Netty Event Loop and configure the DNS settings in the client and use them for all Pulsar client DNS lookups, at least for most common use cases.

Solution

The org.apache.pulsar.client.api.Authentication interface could be changed so that the "container" could pass a context instance with contains methods to lookup shared instances.

    /**
     * Initialize the authentication provider.
     */
    default void start(AuthenticationInitContext context) throws PulsarClientException {
        start();
    }

    /**
     * Initialize the authentication provider.
     */
    void start() throws PulsarClientException;

The AuthenticationInitContext could contain generic "getService" and "getServiceByName" methods:

public interface AuthenticationInitContext {
    <T> Optional<T> getService(Class<T> serviceClass);
    <T> Optional<T> getServiceByName(Class<T> serviceClass, String name);
}

This solution could be used to pass the Netty event loop, DNS resolver and Timer to be shared in the AuthenticationOAuth2 implementation.

Alternatives

No response

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

Labels

type/enhancementThe enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions