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
69
82
94
95 template <typename T>
96 Result receive(TypedMessage<T>& msg, typename TypedMessage<T>::Decoder decoder) {
97 Message rawMsg;
98 auto result = receive(rawMsg);
99 msg = TypedMessage<T>{rawMsg, decoder};
100 return result;
101 }
102
111 Result receive(Message& msg, int timeoutMs);
112
113 template <typename T>
114 Result receive(TypedMessage<T>& msg, int timeoutMs, typename TypedMessage<T>::Decoder decoder) {
115 Message rawMsg;
116 auto result = receive(rawMsg, timeoutMs);
117 msg = TypedMessage<T>{rawMsg, decoder};
118 return result;
119 }
120
132 void receiveAsync(ReceiveCallback callback);
133
134 template <typename T>
135 void receiveAsync(std::function<void(Result result, const TypedMessage<T>&)> callback,
136 typename TypedMessage<T>::Decoder decoder) {
137 receiveAsync([callback, decoder](Result result, const Message& msg) {
138 callback(result, TypedMessage<T>{msg, decoder});
139 });
140 }
141
153
165 void batchReceiveAsync(BatchReceiveCallback callback);
166
178 Result acknowledge(const Message& message);
179
190 Result acknowledge(const MessageId& messageId);
191
196 Result acknowledge(const MessageIdList& messageIdList);
197
207 void acknowledgeAsync(const Message& message, ResultCallback callback);
208
218 void acknowledgeAsync(const MessageId& messageId, ResultCallback callback);
219
226 void acknowledgeAsync(const MessageIdList& messageIdList, ResultCallback callback);
227
246
264
275 void acknowledgeCumulativeAsync(const Message& message, ResultCallback callback);
276
287 void acknowledgeCumulativeAsync(const MessageId& messageId, ResultCallback callback);
288
319 void negativeAcknowledge(const Message& message);
320
351 void negativeAcknowledge(const MessageId& messageId);
352
357
363
368
374
385
399
411 void getBrokerConsumerStatsAsync(BrokerConsumerStatsCallback callback);
412
423 Result seek(const MessageId& messageId);
424
431 Result seek(uint64_t timestamp);
432
443 virtual void seekAsync(const MessageId& messageId, ResultCallback callback);
444
451 virtual void seekAsync(uint64_t timestamp, ResultCallback callback);
452
456 bool isConnected() const;
457
462 void getLastMessageIdAsync(GetLastMessageIdCallback callback);
463
468
469 private:
470 ConsumerImplBasePtr impl_;
471 explicit Consumer(ConsumerImplBasePtr);
472
473 friend class PulsarFriend;
474 friend class PulsarWrapper;
475 friend class MultiTopicsConsumerImpl;
476 friend class ConsumerImpl;
477 friend class ClientImpl;
478 friend class ConsumerTest;
479};
480} // namespace pulsar
481
482#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)
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