pulsar-client-cpp
Loading...
Searching...
No Matches
AutoClusterFailover.h
1
19#ifndef PULSAR_AUTO_CLUSTER_FAILOVER_H_
20#define PULSAR_AUTO_CLUSTER_FAILOVER_H_
21
22#include <pulsar/ServiceInfoProvider.h>
23
24#include <chrono>
25#include <cstdint>
26#include <functional>
27#include <memory>
28#include <vector>
29
30namespace pulsar {
31
32class Client;
33class AutoClusterFailoverImpl;
34
35class PULSAR_PUBLIC AutoClusterFailover final : public ServiceInfoProvider {
36 public:
37 struct Config {
38 const ServiceInfo primary;
39 const std::vector<ServiceInfo> secondary;
40 std::chrono::milliseconds checkInterval{5000}; // 5 seconds
41 uint32_t failoverThreshold{1};
42 uint32_t switchBackThreshold{1};
43
44 Config(ServiceInfo primary, std::vector<ServiceInfo> secondary)
45 : primary(std::move(primary)), secondary(std::move(secondary)) {}
46 };
47
71 class Builder {
72 public:
73 Builder(ServiceInfo primary, std::vector<ServiceInfo> secondary)
74 : config_(std::move(primary), std::move(secondary)) {}
75
76 // Set how frequently probes run against the active cluster(s). Default: 5 seconds.
77 Builder& withCheckInterval(std::chrono::milliseconds interval) {
78 config_.checkInterval = interval;
79 return *this;
80 }
81
82 // Set the number of consecutive failed probes required before attempting failover. Default: 1.
83 Builder& withFailoverThreshold(uint32_t threshold) {
84 config_.failoverThreshold = threshold;
85 return *this;
86 }
87
88 // Set the number of consecutive successful primary probes required before switching back from a
89 // healthy secondary. If the active secondary becomes unavailable and the primary is available,
90 // the implementation may switch back immediately regardless of this threshold. Default: 1.
91 Builder& withSwitchBackThreshold(uint32_t threshold) {
92 config_.switchBackThreshold = threshold;
93 return *this;
94 }
95
96 AutoClusterFailover build() { return AutoClusterFailover(std::move(config_)); }
97
98 private:
99 Config config_;
100 };
101
102 explicit AutoClusterFailover(Config&& config);
103
104 ~AutoClusterFailover() final;
105
107
108 void initialize(std::function<void(ServiceInfo)> onServiceInfoUpdate) final;
109
110 private:
111 std::shared_ptr<AutoClusterFailoverImpl> impl_;
112};
113
114} // namespace pulsar
115
116#endif
void initialize(std::function< void(ServiceInfo)> onServiceInfoUpdate) final
ServiceInfo initialServiceInfo() final
Definition Client.h:52
Definition ServiceInfo.h:33
Definition ServiceInfoProvider.h:28
Definition Authentication.h:31
Definition AutoClusterFailover.h:37