35
35
#include < chrono>
36
36
#include < functional>
37
37
#include " kafka_handle_base.h"
38
- #include " message .h"
38
+ #include " queue .h"
39
39
#include " macros.h"
40
40
#include " error.h"
41
41
@@ -54,7 +54,7 @@ class TopicConfiguration;
54
54
* Semi-simple code showing how to use this class
55
55
*
56
56
* \code
57
- * // Create a configuration and set the group.id and broker list fields
57
+ * // Create a configuration and set the group.id and broker list fields
58
58
* Configuration config = {
59
59
* { "metadata.broker.list", "127.0.0.1:9092" },
60
60
* { "group.id", "foo" }
@@ -74,13 +74,13 @@ class TopicConfiguration;
74
74
* consumer.set_revocation_callback([&](const TopicPartitionList& topic_partitions) {
75
75
* cout << topic_partitions.size() << " partitions revoked!" << endl;
76
76
* });
77
- *
78
- * // Subscribe
77
+ *
78
+ * // Subscribe
79
79
* consumer.subscribe({ "my_topic" });
80
80
* while (true) {
81
81
* // Poll. This will optionally return a message. It's necessary to check if it's a valid
82
82
* // one before using it
83
- * Message msg = consumer.poll();
83
+ * Message msg = consumer.poll();
84
84
* if (msg) {
85
85
* if (!msg.get_error()) {
86
86
* // It's an actual message. Get the payload and print it to stdout
@@ -103,12 +103,12 @@ class CPPKAFKA_API Consumer : public KafkaHandleBase {
103
103
104
104
/* *
105
105
* \brief Creates an instance of a consumer.
106
- *
107
- * Note that the configuration *must contain* the group.id attribute set or this
106
+ *
107
+ * Note that the configuration *must contain* the group.id attribute set or this
108
108
* will throw.
109
109
*
110
110
* \param config The configuration to be used
111
- */
111
+ */
112
112
Consumer (Configuration config);
113
113
Consumer (const Consumer&) = delete ;
114
114
Consumer (Consumer&&) = delete ;
@@ -124,7 +124,7 @@ class CPPKAFKA_API Consumer : public KafkaHandleBase {
124
124
125
125
/* *
126
126
* \brief Sets the topic/partition assignment callback
127
- *
127
+ *
128
128
* The Consumer class will use rd_kafka_conf_set_rebalance_cb and will handle the
129
129
* rebalance, converting from rdkafka topic partition list handles into TopicPartitionList
130
130
* and executing the assignment/revocation/rebalance_error callbacks.
@@ -138,7 +138,7 @@ class CPPKAFKA_API Consumer : public KafkaHandleBase {
138
138
139
139
/* *
140
140
* \brief Sets the topic/partition revocation callback
141
- *
141
+ *
142
142
* The Consumer class will use rd_kafka_conf_set_rebalance_cb and will handle the
143
143
* rebalance, converting from rdkafka topic partition list handles into TopicPartitionList
144
144
* and executing the assignment/revocation/rebalance_error callbacks.
@@ -153,7 +153,7 @@ class CPPKAFKA_API Consumer : public KafkaHandleBase {
153
153
154
154
/* *
155
155
* \brief Sets the rebalance error callback
156
- *
156
+ *
157
157
* The Consumer class will use rd_kafka_conf_set_rebalance_cb and will handle the
158
158
* rebalance, converting from rdkafka topic partition list handles into TopicPartitionList
159
159
* and executing the assignment/revocation/rebalance_error callbacks.
@@ -188,9 +188,9 @@ class CPPKAFKA_API Consumer : public KafkaHandleBase {
188
188
/* *
189
189
* \brief Unassigns the current topic/partition assignment
190
190
*
191
- * This translates into a call to rd_kafka_assign using a null as the topic partition list
191
+ * This translates into a call to rd_kafka_assign using a null as the topic partition list
192
192
* parameter
193
- */
193
+ */
194
194
void unassign ();
195
195
196
196
/* *
@@ -252,7 +252,7 @@ class CPPKAFKA_API Consumer : public KafkaHandleBase {
252
252
*
253
253
* This translates into a call to rd_kafka_get_watermark_offsets
254
254
*
255
- * \param topic_partition The topic/partition to get the offsets from
255
+ * \param topic_partition The topic/partition to get the offsets from
256
256
*/
257
257
OffsetTuple get_offsets (const TopicPartition& topic_partition) const ;
258
258
@@ -316,16 +316,16 @@ class CPPKAFKA_API Consumer : public KafkaHandleBase {
316
316
* This will call rd_kafka_consumer_poll.
317
317
*
318
318
* Note that you need to call poll periodically as a keep alive mechanism, otherwise the broker
319
- * will think this consumer is down and will trigger a rebalance (if using dynamic
319
+ * will think this consumer is down and will trigger a rebalance (if using dynamic
320
320
* subscription).
321
321
*
322
322
* The timeout used on this call will be the one configured via Consumer::set_timeout.
323
323
*
324
324
* The returned message *might* be empty. If's necessary to check that it's a valid one before
325
325
* using it:
326
- *
326
+ *
327
327
* \code
328
- * Message msg = consumer.poll();
328
+ * Message msg = consumer.poll();
329
329
* if (msg) {
330
330
* // It's a valid message!
331
331
* }
@@ -361,6 +361,38 @@ class CPPKAFKA_API Consumer : public KafkaHandleBase {
361
361
* \param timeout The timeout for this operation
362
362
*/
363
363
std::vector<Message> poll_batch (size_t max_batch_size, std::chrono::milliseconds timeout);
364
+
365
+ /* *
366
+ * \brief Get the global event queue servicing this consumer corresponding to
367
+ * rd_kafka_queue_get_main and which is polled via rd_kafka_poll
368
+ *
369
+ * \return A Queue object
370
+ *
371
+ * \remark Note that this call will disable forwarding to the consumer_queue.
372
+ * To restore forwarding (if desired) call Queue::forward_to_queue(consumer_queue)
373
+ */
374
+ Queue get_main_queue () const ;
375
+
376
+ /* *
377
+ * \brief Get the consumer group queue servicing corresponding to
378
+ * rd_kafka_queue_get_consumer and which is polled via rd_kafka_consumer_poll
379
+ *
380
+ * \return A Queue object
381
+ */
382
+ Queue get_consumer_queue () const ;
383
+
384
+ /* *
385
+ * \brief Get the queue belonging to this partition. If the consumer is not assigned to this
386
+ * partition, an empty queue will be returned
387
+ *
388
+ * \param partition The partition object
389
+ *
390
+ * \return A Queue object
391
+ *
392
+ * \remark Note that this call will disable forwarding to the consumer_queue.
393
+ * To restore forwarding (if desired) call Queue::forward_to_queue(consumer_queue)
394
+ */
395
+ Queue get_partition_queue (const TopicPartition& partition) const ;
364
396
private:
365
397
static void rebalance_proxy (rd_kafka_t *handle, rd_kafka_resp_err_t error,
366
398
rd_kafka_topic_partition_list_t *partitions, void *opaque);
0 commit comments