You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`Properties` is a map which contains all configuration info needed to initialize a Kafka client. These configuration items are key-value pairs, -- the "key" is a `std::string`, while the "value" could be a `std::string`, a `std::function<...>`, or an `Interceptors`.
168
169
169
-
* In most cases, the `Properties` settings for ***modern-cpp-kafka*** are identical with [librdkafka configuration](https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md)
170
+
* K-V Types: `std::string` -> `std::string`
170
171
171
-
* With following exceptions
172
+
* Most are identical with [librdkafka configuration](https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md)
172
173
173
-
* KafkaConsumer
174
+
* But with Exceptions
174
175
175
-
* Properties with random string as default
176
+
* Default Value Changes
176
177
177
-
* `client.id`
178
+
* `log_level`(default: `5`): default was `6` from **librdkafka**
178
179
179
-
* `group.id`
180
+
* `client.id` (default: random string): no default string from **librdkafka**
180
181
181
-
* More properties than ***librdkafka***
182
+
* `group.id` (default: random string, for `KafkaConsumer` only): no default string from **librdkafka**
182
183
183
-
* `max.poll.records` (default: `500`): The maxmum number of records that a single call to `poll()` would return
184
+
* Additional Options
184
185
185
-
* Property which overrides the one from ***librdkafka***
186
+
* `enable.manual.events.poll` (default: `false`): To poll the (offset-commit/message-delivery callback) events manually
186
187
187
-
* `enable.auto.commit` (default: `false`): To automatically commit the previously polled offsets on each `poll` operation
188
+
* `max.poll.records` (default: `500`, for `KafkaConsumer` only): The maxmum number of records that a single call to `poll()` would return
188
189
189
-
* Properties not supposed to be used (internally shadowed by ***modern-cpp-kafka***)
190
+
* Ignored Options
190
191
191
-
* `enable.auto.offset.store`
192
+
* `enable.auto.offset.store`: ***modern-cpp-kafka*** will save the offsets in its own way
192
193
193
-
* `auto.commit.interval.ms`
194
+
* `auto.commit.interval.ms`: ***modern-cpp-kafka*** will not commit the offsets periodically, instead, it would do it in the next `poll()`.
Copy file name to clipboardExpand all lines: doc/KafkaConsumerQuickStart.md
+18-20Lines changed: 18 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,8 +4,6 @@ Generally speaking, The `Modern C++ Kafka API` is quite similar with [Kafka Java
4
4
5
5
We'd recommend users to cross-reference them, --especially the examples.
6
6
7
-
Unlike Java's KafkaConsumer, here we introduced two derived classes, --KafkaAutoCommitConsumer and KafkaManualCommitConsumer, --depending on whether users should call `commit` manually.
8
-
9
7
## KafkaConsumer (`enable.auto.commit=true`)
10
8
11
9
* Automatically commits previously polled offsets on each `poll` (and the final `close`) operations.
@@ -15,13 +13,12 @@ Unlike Java's KafkaConsumer, here we introduced two derived classes, --KafkaAuto
15
13
### Example
16
14
```cpp
17
15
// Create configuration object
18
-
kafka::Properties props ({
19
-
{"bootstrap.servers", brokers},
20
-
{"enable.auto.commit", "true"}
16
+
const Properties props ({
17
+
{"bootstrap.servers", {brokers}},
21
18
});
22
19
23
20
// Create a consumer instance
24
-
kafka::clients::KafkaConsumer consumer(props);
21
+
KafkaConsumer consumer(props);
25
22
26
23
// Subscribe to topics
27
24
consumer.subscribe({topic});
@@ -40,15 +37,15 @@ Unlike Java's KafkaConsumer, here we introduced two derived classes, --KafkaAuto
@@ -124,21 +122,21 @@ Unlike Java's KafkaConsumer, here we introduced two derived classes, --KafkaAuto
124
122
// consumer.close(); // No explicit close is needed, RAII will take care of it
125
123
```
126
124
127
-
* The example is quite similar with the KafkaAutoCommitConsumer, with only 1 more line added for manual-commit.
125
+
* The example is quite similar with the previous `enable.auto.commit=true` case, but has to call `commitSync`(or `commitAsync`) manually.
128
126
129
-
*`commitSync` and `commitAsync` are both available for a KafkaManualConsumer. Normally, use `commitSync` to guarantee the commitment, or use `commitAsync`(with `OffsetCommitCallback`) to get a better performance.
127
+
*`commitSync` and `commitAsync` are both available here. Normally, use `commitSync` to guarantee the commitment, or use `commitAsync`(with `OffsetCommitCallback`) to get a better performance.
130
128
131
-
## `KafkaConsumer` with `kafka::clients::KafkaClient::EventsPollingOption`
129
+
## Option `enable.manual.events.poll`
132
130
133
-
While we construct a `KafkaConsumer` with `kafka::clients::KafkaClient::EventsPollingOption::Auto` (i.e. the default option), an internal thread would be created for `OffsetCommit` callbacks handling.
131
+
While we construct a `KafkaConsumer` with `enable.manual.events.poll=false` (i.e. the default option), an internal thread would be created for `OffsetCommit` callbacks handling.
134
132
135
133
This might not be what you want, since then you have to use 2 different threads to process the messages and handle the `OffsetCommit` responses.
136
134
137
-
Here we have another choice, -- using `kafka::clients::KafkaClient::EventsPollingOption::Manual`, thus the `OffsetCommit` callbacks would be called within member function `pollEvents()`.
135
+
Here we have another choice, -- using `enable.manual.events.poll=true`, thus the `OffsetCommit` callbacks would be called within member function `pollEvents()`.
@@ -60,32 +62,32 @@ We'd recommend users to cross-reference them, --especially the examples.
60
62
61
63
## `KafkaProducer` with `kafka::clients::KafkaClient::EventsPollingOption`
62
64
63
-
While we construct a `KafkaProducer` with `kafka::clients::KafkaClient::EventsPollingOption::Auto` (the default option), an internal thread would be created for `MessageDelivery` callbacks handling.
65
+
While we construct a `KafkaProducer` with `enable.manual.events.poll=false` (the default option), an internal thread would be created for `MessageDelivery` callbacks handling.
64
66
65
67
This might not be what you want, since then you have to use 2 different threads to send the messages and handle the `MessageDelivery` responses.
66
68
67
-
Here we have another choice, -- using `kafka::clients::KafkaClient::EventsPollingOption::Manual`, thus the `MessageDelivery` callbacks would be called within member function `pollEvents()`.
69
+
Here we have another choice, -- using `enable.manual.events.poll=true`, thus the `MessageDelivery` callbacks would be called within member function `pollEvents()`.
68
70
69
-
* Note, if you constructed the `KafkaProducer` with `EventsPollingOption::Manual`, the `send()` would be an `unblocked` operation.
70
-
I.e, once the `message buffering queue` becomes full, the `send()` operation would throw an exception (or return an `error code` with the input reference parameter), -- instead of blocking there.
71
-
This makes sense, since you might want to call `pollEvents()` later, thus delivery-callback could be called for some messages (which could then be removed from the `message buffering queue`).
71
+
* Note, if you constructed the `KafkaProducer` with `enable.manual.events.poll=true`, the `send()` will be an `unblocked` operation even if the `message buffering queue` is full. In that case, the `send()` operation would throw an exception (or return an `error code` with the input reference parameter), -- instead of blocking there. And you might want to call `pollEvents()`, thus delivery-callback could be called for some messages (which could then be removed from the `message buffering queue`).
0 commit comments