feat kafka: added seek functionality for consumer.#948
Conversation
| if (event_type == kafka::RebalanceEventType::kAssigned) { | ||
| for (const auto& topic_partitions : partitions) { | ||
| UEXPECT_NO_THROW(consumer_scope.SeekToBeginning( | ||
| std::string(topic_partitions.topic), topic_partitions.partition_id, poll_timeout |
There was a problem hiding this comment.
давай тоже utils::zstring_view принимать, а то как-то неудобно выходит))
| kafka::utest::Message{topic, "key", "value", 0, kHeaders}, | ||
| kafka::utest::Message{topic, "key2", "value2", 0, kHeaders}, | ||
| }; | ||
| const std::uint64_t kMessagesToSkip = 1; |
There was a problem hiding this comment.
давай сделаем 10 сообщений и 7 в skip
| static constexpr std::array kExpectedHeaders{kafka::HeaderView{"header-1", "value-1"}}; | ||
| const std::vector<kafka::OwningHeader> kHeaders{kExpectedHeaders.begin(), kExpectedHeaders.end()}; |
| const std::array kMessages{ | ||
| kafka::utest::Message{topic, "key", "value", 0, kHeaders}, | ||
| kafka::utest::Message{topic, "key2", "value2", 0, kHeaders}, |
There was a problem hiding this comment.
- давай больше сообщений
- можем сделать два раза Receive? Сначала без сик, прочитываем всё до конца, потом делаем сик, потом заново всё прочитываем
| }); | ||
|
|
||
| const auto* err = rd_kafka_seek_partitions( | ||
| consumer_.GetHandle(), topic_partitions_list.GetHandle(), static_cast<int>(timeout.count()) |
There was a problem hiding this comment.
тут получается 2 * timeout. В этом месте уже должно быть timeout - время на poll
|
|
||
| // Added `rd_kafka_queue_poll` call to activate the assign operation | ||
| // if it is called from RebalanceCallback. | ||
| { EventHolder event{rd_kafka_queue_poll(consumer_.GetQueue(), static_cast<int>(timeout.count()))}; } |
There was a problem hiding this comment.
а если пришёл месседж в эвент? просто скрипнем?
выглядит как-то очень странно, кмк
а если вызывано не из rebalance callback?
There was a problem hiding this comment.
Так мы всё равно seek делаем, если мессадж ивент придёт, то нам как бы пофиг на него, мы на другой offset скачем же. Тут самое фиговое если ещё раз ребаланс прилетит, но после успешного assign и revoke такого быть не должно судя по всему.
Seek,SeekToBeginning,SeekToEnd,SeekToEndfunctions toConsumerScopeclass.RebalanceCallbackfor a consumer which is called after assign/revoke partitions occurs.Note: by creating a PR or an issue you automatically agree to the CLA. See CONTRIBUTING.md. Feel free to remove this note, the agreement holds.