pulsar-client-cpp
Loading...
Searching...
No Matches
Consumer.h
1
19#ifndef CONSUMER_HPP_
20#define CONSUMER_HPP_
21
22#include <pulsar/BrokerConsumerStats.h>
23#include <pulsar/ConsumerConfiguration.h>
24#include <pulsar/TypedMessage.h>
25#include <pulsar/defines.h>
26
27#include <iostream>
28
29namespace pulsar {
30class PulsarWrapper;
31class ConsumerImplBase;
32class PulsarFriend;
33typedef std::shared_ptr<ConsumerImplBase> ConsumerImplBasePtr;
37class PULSAR_PUBLIC Consumer {
38 public:
43 virtual ~Consumer() = default;
44
48 const std::string& getTopic() const;
49
53 const std::string& getSubscriptionName() const;
54
58 const std::string& getConsumerName() const;
59
74
87
99
100 template <typename T>
101 Result receive(TypedMessage<T>& msg, typename TypedMessage<T>::Decoder decoder) {
102 Message rawMsg;
103 auto result = receive(rawMsg);
104 msg = TypedMessage<T>{rawMsg, decoder};
105 return result;
106 }
107
116 Result receive(Message& msg, int timeoutMs);
117
118 template <typename T>
119 Result receive(TypedMessage<T>& msg, int timeoutMs, typename TypedMessage<T>::Decoder decoder) {
120 Message rawMsg;
121 auto result = receive(rawMsg, timeoutMs);
122 msg = TypedMessage<T>{rawMsg, decoder};
123 return result;
124 }
125
137 void receiveAsync(ReceiveCallback callback);
138
139 template <typename T>
140 void receiveAsync(std::function<void(Result result, const TypedMessage<T>&)> callback,
141 typename TypedMessage<T>::Decoder decoder) {
142 receiveAsync([callback, decoder](Result result, const Message& msg) {
143 callback(result, TypedMessage<T>{msg, decoder});
144 });
145 }
146
158
170 void batchReceiveAsync(BatchReceiveCallback callback);
171
183 Result acknowledge(const Message& message);
184
195 Result acknowledge(const MessageId& messageId);
196
201 Result acknowledge(const MessageIdList& messageIdList);
202
212 void acknowledgeAsync(const Message& message, ResultCallback callback);
213
223 void acknowledgeAsync(const MessageId& messageId, ResultCallback callback);
224
231 void acknowledgeAsync(const MessageIdList& messageIdList, ResultCallback callback);
232
251
269
280 void acknowledgeCumulativeAsync(const Message& message, ResultCallback callback);
281
292 void acknowledgeCumulativeAsync(const MessageId& messageId, ResultCallback callback);
293
324 void negativeAcknowledge(const Message& message);
325
356 void negativeAcknowledge(const MessageId& messageId);
357
362
368
373
379
390
404
416 void getBrokerConsumerStatsAsync(BrokerConsumerStatsCallback callback);
417
428 Result seek(const MessageId& messageId);
429
436 Result seek(uint64_t timestamp);
437
448 virtual void seekAsync(const MessageId& messageId, ResultCallback callback);
449
456 virtual void seekAsync(uint64_t timestamp, ResultCallback callback);
457
461 bool isConnected() const;
462
467 void getLastMessageIdAsync(GetLastMessageIdCallback callback);
468
473
474 private:
475 ConsumerImplBasePtr impl_;
476 explicit Consumer(ConsumerImplBasePtr);
477
478 friend class PulsarFriend;
479 friend class PulsarWrapper;
480 friend class MultiTopicsConsumerImpl;
481 friend class ConsumerImpl;
482 friend class ClientImpl;
483 friend class ConsumerTest;
484};
485} // namespace pulsar
486
487#endif /* CONSUMER_HPP_ */
Definition BrokerConsumerStats.h:35
Definition Consumer.h:37
virtual void seekAsync(uint64_t timestamp, ResultCallback callback)
void receiveAsync(ReceiveCallback callback)
void getBrokerConsumerStatsAsync(BrokerConsumerStatsCallback callback)
Result resumeMessageListener()
void closeAsync(ResultCallback callback)
void acknowledgeAsync(const MessageId &messageId, ResultCallback callback)
Result acknowledge(const Message &message)
void negativeAcknowledge(const Message &message)
void redeliverUnacknowledgedMessages()
Result acknowledgeCumulative(const Message &message)
Result seek(const MessageId &messageId)
Result batchReceive(Messages &msgs)
Result unsubscribe()
Result acknowledge(const MessageIdList &messageIdList)
void acknowledgeCumulativeAsync(const MessageId &messageId, ResultCallback callback)
Result getBrokerConsumerStats(BrokerConsumerStats &brokerConsumerStats)
void acknowledgeCumulativeAsync(const Message &message, ResultCallback callback)
Result pauseMessageListener()
void acknowledgeAsync(const MessageIdList &messageIdList, ResultCallback callback)
Result acknowledgeCumulative(const MessageId &messageId)
const std::string & getConsumerName() const
void acknowledgeAsync(const Message &message, ResultCallback callback)
void unsubscribeAsync(ResultCallback callback)
bool isConnected() const
Result receive(Message &msg)
void batchReceiveAsync(BatchReceiveCallback callback)
Result receive(Message &msg, int timeoutMs)
const std::string & getTopic() const
Result seek(uint64_t timestamp)
Result acknowledge(const MessageId &messageId)
virtual void seekAsync(const MessageId &messageId, ResultCallback callback)
const std::string & getSubscriptionName() const
Result getLastMessageId(MessageId &messageId)
void getLastMessageIdAsync(GetLastMessageIdCallback callback)
void negativeAcknowledge(const MessageId &messageId)
Definition Message.h:44
Definition MessageId.h:34
Definition TypedMessage.h:28
Definition Authentication.h:31
std::vector< Message > Messages
Callback definition for non-data operation.
Definition ConsumerConfiguration.h:49
std::function< void(Result result)> ResultCallback
Callback definition for non-data operation.
Definition ConsumerConfiguration.h:50
Result
Definition Result.h:32