Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client switch connection between different pulsar cluster. #2551

Closed
codelipenghui opened this issue Sep 10, 2018 · 4 comments
Closed

Client switch connection between different pulsar cluster. #2551

codelipenghui opened this issue Sep 10, 2018 · 4 comments
Assignees
Labels
type/feature The PR added a new feature or issue requested a new feature

Comments

@codelipenghui
Copy link
Contributor

codelipenghui commented Sep 10, 2018

It's necessary to add a mechanism to support client switch connection between different pulsar cluster.

Motivation

Generally, we can use DNS or TCP proxy to improve broker availability when you have many pulsar cluster and one cluster is not available(such as network error). But in this solution, we need a backup cluster, the backup cluster has the same configurations. And in this solution have a problem with only can close connection by broker(shut down the broker or setting the network or offload namespace) to trigger client reconnect. So i have a idea, we can trigger client reconnect by pulsar client.

Implement

By now, we can create a pulsar client use service url. We can add a method named serviceUrlProvider to create a pulsar client.

public interface ServiceUrlProvider {

    /**
     * Get pulsar service url from ServiceUrlProvider.
     *
     * @return pulsar service url.
     */
    String getServiceUrl();

    /**
     * Set pulsar client to the provider for provider can control the pulsar client,
     * such as {@link PulsarClient#forceCloseConnection()} or {@link PulsarClient#close()}.
     *
     * @param client created pulsar client.
     */
    void setClient(PulsarClient client);

}

We can create custom provider by ServiceUrlProvider such as ZookeeperServiceUrlProvider. ZookeeperServiceUrlProvider can watch zookeeper node update event then trigger pulsar client to reconnect the new service url. We can add method like this:

public void onServiceUrlChanged(String newServiceUrl) throws PulsarClientException {
            this.getPulsarClient().getConf().setServiceUrl(newServiceUrl);
            this.getPulsarClient().reloadLookUp();
            this.getPulsarClient().forceCloseConnection();
        }

In this solution we switch client connection simpler and no need to do any thing in pulsar broker.

Already have a PR for this issue 2543

@sijie
Copy link
Member

sijie commented Sep 12, 2018

This issue is being implemented on #2543

@sijie sijie added type/feature The PR added a new feature or issue requested a new feature triage/week-37 labels Sep 12, 2018
@Carl-Hee
Copy link

@sijie Is dns necessary, or can we use IP address directly?

@codelipenghui
Copy link
Contributor Author

#2671 Refactored to simplify API for adding ServiceUrlProvider

use

this.getPulsarClient().updateServiceUrl(newServiceUrl);

replace

this.getPulsarClient().getConf().setServiceUrl(newServiceUrl);
this.getPulsarClient().reloadLookUp();
this.getPulsarClient().forceCloseConnection();

@sijie
Copy link
Member

sijie commented Dec 27, 2018

This is fixed by #2543 #2671

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature The PR added a new feature or issue requested a new feature
Projects
None yet
Development

No branches or pull requests

3 participants