pulsar-client-cpp
Loading...
Searching...
No Matches
Client.h
1
19#ifndef PULSAR_CLIENT_HPP_
20#define PULSAR_CLIENT_HPP_
21
22#include <pulsar/ClientConfiguration.h>
23#include <pulsar/ConsoleLoggerFactory.h>
24#include <pulsar/Consumer.h>
25#include <pulsar/FileLoggerFactory.h>
26#include <pulsar/Message.h>
27#include <pulsar/MessageBuilder.h>
28#include <pulsar/Producer.h>
29#include <pulsar/Reader.h>
30#include <pulsar/Result.h>
31#include <pulsar/Schema.h>
32#include <pulsar/ServiceInfo.h>
33#include <pulsar/ServiceInfoProvider.h>
34#include <pulsar/TableView.h>
35#include <pulsar/defines.h>
36
37#include <memory>
38#include <string>
39#include <utility>
40#include <variant>
41#include <vector>
42
43namespace pulsar {
44typedef std::function<void(Result, Producer)> CreateProducerCallback;
45typedef std::function<void(Result, Consumer)> SubscribeCallback;
46typedef std::function<void(Result, Reader)> ReaderCallback;
47typedef std::function<void(Result, TableView)> TableViewCallback;
48typedef std::function<void(Result, const std::vector<std::string>&)> GetPartitionsCallback;
49typedef std::function<void(Result)> CloseCallback;
50
51using CreateProducerV2Callback = std::function<void(std::variant<Error, Producer>)>;
52using CreateConsumerV2Callback = std::function<void(std::variant<Error, Consumer>)>;
53using SubscribeV2Callback = CreateConsumerV2Callback;
54using ReaderV2Callback = std::function<void(std::variant<Error, Reader>)>;
55using TableViewV2Callback = std::function<void(std::variant<Error, TableView>)>;
56
60struct TopicRegex {
61 explicit TopicRegex(std::string pattern) : pattern(std::move(pattern)) {}
62
63 std::string pattern;
64};
65
66using SubscribeTopics = std::variant<std::string, std::vector<std::string>, TopicRegex>;
67
68class ClientImpl;
69class PulsarFriend;
70class PulsarWrapper;
71
72class PULSAR_PUBLIC Client {
73 public:
81 Client(const std::string& serviceUrl);
82
92 Client(const std::string& serviceUrl, const ClientConfiguration& clientConfiguration);
93
105 static Client create(std::unique_ptr<ServiceInfoProvider> serviceInfoProvider,
106 const ClientConfiguration& clientConfiguration);
107
118 Result createProducer(const std::string& topic, Producer& producer);
119
131 [[deprecated("use createProducerV2")]] Result createProducer(const std::string& topic,
132 const ProducerConfiguration& conf,
133 Producer& producer);
134
143 [[deprecated("use createProducerAsyncV2")]] void createProducerAsync(
144 const std::string& topic, const CreateProducerCallback& callback);
145
153 [[deprecated("use createProducerAsyncV2")]] void createProducerAsync(
154 const std::string& topic, const ProducerConfiguration& conf, const CreateProducerCallback& callback);
155
156 void createProducerAsyncV2(const std::string& topic, const ProducerConfiguration& conf,
157 CreateProducerV2Callback callback);
158
159 std::variant<Error, Producer> createProducerV2(const std::string& topic,
160 const ProducerConfiguration& conf);
161
170 Result subscribe(const std::string& topic, const std::string& subscriptionName, Consumer& consumer);
171
180 Result subscribe(const std::string& topic, const std::string& subscriptionName,
181 const ConsumerConfiguration& conf, Consumer& consumer);
182
192 void subscribeAsync(const std::string& topic, const std::string& subscriptionName,
193 const SubscribeCallback& callback);
194
205 void subscribeAsync(const std::string& topic, const std::string& subscriptionName,
206 const ConsumerConfiguration& conf, const SubscribeCallback& callback);
207
208 void subscribeAsyncV2(const SubscribeTopics& topics, const std::string& subscriptionName,
209 const ConsumerConfiguration& conf, SubscribeV2Callback callback);
210
211 std::variant<Error, Consumer> subscribeV2(const SubscribeTopics& topics,
212 const std::string& subscriptionName,
213 const ConsumerConfiguration& conf);
214
222 Result subscribe(const std::vector<std::string>& topics, const std::string& subscriptionName,
223 Consumer& consumer);
224
233 Result subscribe(const std::vector<std::string>& topics, const std::string& subscriptionName,
234 const ConsumerConfiguration& conf, Consumer& consumer);
235
246 void subscribeAsync(const std::vector<std::string>& topics, const std::string& subscriptionName,
247 const SubscribeCallback& callback);
248
259 void subscribeAsync(const std::vector<std::string>& topics, const std::string& subscriptionName,
260 const ConsumerConfiguration& conf, const SubscribeCallback& callback);
261
265 Result subscribeWithRegex(const std::string& regexPattern, const std::string& subscriptionName,
266 Consumer& consumer);
267
272 Result subscribeWithRegex(const std::string& regexPattern, const std::string& subscriptionName,
273 const ConsumerConfiguration& conf, Consumer& consumer);
274
282 void subscribeWithRegexAsync(const std::string& regexPattern, const std::string& subscriptionName,
283 const SubscribeCallback& callback);
284
295 void subscribeWithRegexAsync(const std::string& regexPattern, const std::string& subscriptionName,
296 const ConsumerConfiguration& conf, const SubscribeCallback& callback);
297
327 Result createReader(const std::string& topic, const MessageId& startMessageId,
328 const ReaderConfiguration& conf, Reader& reader);
329
356 void createReaderAsync(const std::string& topic, const MessageId& startMessageId,
357 const ReaderConfiguration& conf, const ReaderCallback& callback);
358
359 void createReaderAsyncV2(const std::string& topic, const MessageId& startMessageId,
360 const ReaderConfiguration& conf, ReaderV2Callback callback);
361
362 std::variant<Error, Reader> createReaderV2(const std::string& topic, const MessageId& startMessageId,
363 const ReaderConfiguration& conf);
364
377 Result createTableView(const std::string& topic, const TableViewConfiguration& conf,
378 TableView& tableView);
379
392 void createTableViewAsync(const std::string& topic, const TableViewConfiguration& conf,
393 const TableViewCallback& callBack);
394
395 void createTableViewAsyncV2(const std::string& topic, const TableViewConfiguration& conf,
396 TableViewV2Callback callback);
397
398 std::variant<Error, TableView> createTableViewV2(const std::string& topic,
399 const TableViewConfiguration& conf);
400
414 Result getPartitionsForTopic(const std::string& topic, std::vector<std::string>& partitions);
415
431 void getPartitionsForTopicAsync(const std::string& topic, const GetPartitionsCallback& callback);
432
438
448 void closeAsync(const CloseCallback& callback);
449
456 void shutdown();
457
464
471
479 void getSchemaInfoAsync(const std::string& topic, int64_t version,
480 std::function<void(Result, const SchemaInfo&)> callback);
481
488
489 private:
490 Client(const std::shared_ptr<ClientImpl>&);
491
492 friend class PulsarFriend;
493 friend class PulsarWrapper;
494 std::shared_ptr<ClientImpl> impl_;
495};
496} // namespace pulsar
497
498#endif /* PULSAR_CLIENT_HPP_ */
Definition ClientConfiguration.h:31
static Client create(std::unique_ptr< ServiceInfoProvider > serviceInfoProvider, const ClientConfiguration &clientConfiguration)
void closeAsync(const CloseCallback &callback)
Result subscribeWithRegex(const std::string &regexPattern, const std::string &subscriptionName, Consumer &consumer)
void subscribeAsync(const std::string &topic, const std::string &subscriptionName, const ConsumerConfiguration &conf, const SubscribeCallback &callback)
Result subscribeWithRegex(const std::string &regexPattern, const std::string &subscriptionName, const ConsumerConfiguration &conf, Consumer &consumer)
uint64_t getNumberOfConsumers()
Get the number of alive consumers on the current client.
Result subscribe(const std::string &topic, const std::string &subscriptionName, const ConsumerConfiguration &conf, Consumer &consumer)
Client(const std::string &serviceUrl, const ClientConfiguration &clientConfiguration)
Result getPartitionsForTopic(const std::string &topic, std::vector< std::string > &partitions)
void subscribeAsync(const std::string &topic, const std::string &subscriptionName, const SubscribeCallback &callback)
void subscribeAsync(const std::vector< std::string > &topics, const std::string &subscriptionName, const SubscribeCallback &callback)
void subscribeWithRegexAsync(const std::string &regexPattern, const std::string &subscriptionName, const SubscribeCallback &callback)
void createReaderAsync(const std::string &topic, const MessageId &startMessageId, const ReaderConfiguration &conf, const ReaderCallback &callback)
ServiceInfo getServiceInfo() const
void createProducerAsync(const std::string &topic, const ProducerConfiguration &conf, const CreateProducerCallback &callback)
uint64_t getNumberOfProducers()
Get the number of alive producers on the current client.
void createProducerAsync(const std::string &topic, const CreateProducerCallback &callback)
Result subscribe(const std::vector< std::string > &topics, const std::string &subscriptionName, const ConsumerConfiguration &conf, Consumer &consumer)
Result createProducer(const std::string &topic, Producer &producer)
Result subscribe(const std::string &topic, const std::string &subscriptionName, Consumer &consumer)
void getSchemaInfoAsync(const std::string &topic, int64_t version, std::function< void(Result, const SchemaInfo &)> callback)
void subscribeAsync(const std::vector< std::string > &topics, const std::string &subscriptionName, const ConsumerConfiguration &conf, const SubscribeCallback &callback)
Result createProducer(const std::string &topic, const ProducerConfiguration &conf, Producer &producer)
Result createTableView(const std::string &topic, const TableViewConfiguration &conf, TableView &tableView)
Result close()
Client(const std::string &serviceUrl)
void subscribeWithRegexAsync(const std::string &regexPattern, const std::string &subscriptionName, const ConsumerConfiguration &conf, const SubscribeCallback &callback)
void createTableViewAsync(const std::string &topic, const TableViewConfiguration &conf, const TableViewCallback &callBack)
Result createReader(const std::string &topic, const MessageId &startMessageId, const ReaderConfiguration &conf, Reader &reader)
Result subscribe(const std::vector< std::string > &topics, const std::string &subscriptionName, Consumer &consumer)
void getPartitionsForTopicAsync(const std::string &topic, const GetPartitionsCallback &callback)
Definition ConsumerConfiguration.h:65
Definition Consumer.h:37
Definition MessageId.h:34
Definition ProducerConfiguration.h:46
Definition Producer.h:36
Definition ReaderConfiguration.h:49
Definition Reader.h:37
Definition Schema.h:147
Definition ServiceInfo.h:33
Definition TableView.h:38
Definition Authentication.h:31
Result
Definition Result.h:35
Definition TableViewConfiguration.h:27
Definition Client.h:60