[GitHub] [pulsar-client-cpp] shibd commented on pull request #170: [feature] Support set ServiceUrlProvider when create client.
shibd commented on PR #170: URL: https://github.com/apache/pulsar-client-cpp/pull/170#issuecomment-1396581433 > In short, a natural design is to save the `ServiceUrlProvider` in `Client` and call `getServiceUrl()` method (in C++ it's just a function invocation) each time we need a service URL. Maybe we need to maintain a key-value (`serviceUrl -> ServiceNameResolver`), when the `serviceUrlProvider()` returns a different result from the key, creating a new `ServiceNameResolver` for related lookup requests. I think you only need the client to provide the `updateServiceUrl` method. Users can take advantage of this approach to implement their own services. (Pseudocode) ```c++ class Store; class AutomaticClusterService { public: explicit AutomaticClusterService(const Store& store, const Client pulsarClient) : store_(store), pulsarClient_(pulsarClient) { serviceUrlCache_ = store.queryServiceUrl(); updateServiceUrlInterval_ = boost::posix_time::seconds(60); runUpdateServiceurl(); } void start() { runUpdateServiceurl(); } const std::string& getServiceUrl(){ return serviceUrlCache_; } const void runUpdateServiceurl() { timer_->expires_from_now(updateServiceUrlInterval_); auto availableServiceUrl = store_.queryServiceUrl(); timer_->async_wait([this](const boost::system::error_code& ec) { // Maybe some other implementation if (serviceUrlCache_ != availableServiceUrl) { serviceUrlCache_ = availableServiceUrl; pulsarClient_.updateServiceUrl(serviceUrlCache_); } runUpdateServiceurl(); }); } private: // External storage services Store store_; const Client pulsarClient_; std::string serviceUrlCache_; std::shared_ptr timer_; boost::posix_time::time_duration updateServiceUrlInterval_; }; Store store; Client client(store.queryServiceUrl()); AutomaticClusterService automaticClusterService(store, client); automaticClusterService.start(); // ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [pulsar-client-cpp] shibd commented on pull request #170: [feature] Support set ServiceUrlProvider when create client.
shibd commented on PR #170: URL: https://github.com/apache/pulsar-client-cpp/pull/170#issuecomment-1396555980 If you feel redundant to expose this method, I can remove it. What do you think? /cc @BewareMyPower -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [pulsar-client-cpp] shibd commented on pull request #170: [feature] Support set ServiceUrlProvider when create client.
shibd commented on PR #170: URL: https://github.com/apache/pulsar-client-cpp/pull/170#issuecomment-1396552263 > If we want to implement AutoClusterFailover and ControlledClusterFailover in future, we actually don't need to implement a function that returns the service URL. Instead, we only need to implement the following methods: Yes, Actually, the `ServiceUrlProvider ` implemented here is just convenient for the user to return a function in order to get the service URL from elsewhere. If we do not expose the set `ServiceUrlProvider`, It's no problem too. Use `ServiceUrlProvider` ```c++ Client client([]() { // get service URL from store. auto serviceUrl = xxx return serviceUrl; }) ``` `ServiceUrlProvider` is not used ```c++ // get service URL from store. auto serviceUrl = xxx Client client(serviceUrl); ``` I exposed it just for ease of use. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [pulsar-client-cpp] shibd commented on pull request #170: [feature] Support set ServiceUrlProvider when create client.
shibd commented on PR #170: URL: https://github.com/apache/pulsar-client-cpp/pull/170#issuecomment-1381605478 > We only need to support passing a std::function. The initialize and close methods are redundant. Yes, you are right. The initialize and close methods are redundant. In fact, The client already provides the `updateServiceUrl` method, which the user can use to implement dynamic update service URL. As for how the user implements it and how to close his resources, this is left to the user. I changed to pass a `std::function` when creating a `Client`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [pulsar-client-cpp] shibd commented on pull request #170: [feature] Support set ServiceUrlProvider when create client.
shibd commented on PR #170: URL: https://github.com/apache/pulsar-client-cpp/pull/170#issuecomment-1381406248 > We only need to support passing a std::function. The initialize and close methods are redundant. The initialize and close methods are useful. We need pass `Client&` to `ServiceUrlProvider` by `initialize` method. https://github.com/apache/pulsar-client-cpp/blob/7d91638513405ed3e9bc5e7cd782d30e8703679d/lib/Client.cc#L43 This way, if the user implements the `ServiceUrlProvider`. When it listens for a change in the service URL (such as through zk or other storage), it can invoke the `client.updateServiceUrl` method to update the URL. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org