File tree 6 files changed +54
-0
lines changed
6 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1
1
build
2
+ include /cppkafka /config.h
Original file line number Diff line number Diff line change @@ -34,6 +34,18 @@ include_directories(${Boost_INCLUDE_DIRS})
34
34
find_package (RdKafka REQUIRED)
35
35
include_directories (${RDKAFKA_INCLUDE_DIR} )
36
36
37
+ if (HAVE_OFFSETS_FOR_TIMES)
38
+ message (STATUS "Enabling support for KafkaHandleBase::get_offsets_for_times" )
39
+ set (CPPKAFKA_HAVE_OFFSET_FOR_TIMES ON )
40
+ else ()
41
+ message (STATUS "Disabling support for KafkaHandleBase::get_offsets_for_times" )
42
+ endif ()
43
+ # Configuration file
44
+ configure_file (
45
+ "${PROJECT_SOURCE_DIR} /include/cppkafka/config.h.in"
46
+ "${PROJECT_SOURCE_DIR} /include/cppkafka/config.h"
47
+ )
48
+
37
49
add_subdirectory (src)
38
50
add_subdirectory (include )
39
51
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ include(CheckFunctionExists)
24
24
25
25
set (CMAKE_REQUIRED_LIBRARIES ${RDKAFKA_LIBRARY} )
26
26
check_function_exists(rd_kafka_committed HAVE_VALID_KAFKA_VERSION)
27
+ check_function_exists(rd_kafka_offsets_for_times HAVE_OFFSETS_FOR_TIMES)
27
28
set (CMAKE_REQUIRED_LIBRARIES)
28
29
29
30
if (HAVE_VALID_KAFKA_VERSION)
Original file line number Diff line number Diff line change
1
+ #ifndef CPPKAFKA_CONFIG_H
2
+ #define CPPKAFKA_CONFIG_H
3
+
4
+ #cmakedefine CPPKAFKA_HAVE_OFFSET_FOR_TIMES
5
+
6
+ #endif // CPPKAFKA_CONFIG_H
Original file line number Diff line number Diff line change 34
34
#include < memory>
35
35
#include < chrono>
36
36
#include < unordered_map>
37
+ #include < map>
37
38
#include < mutex>
38
39
#include < tuple>
40
+ #include < chrono>
39
41
#include < librdkafka/rdkafka.h>
40
42
#include " topic_partition.h"
41
43
#include " topic_partition_list.h"
42
44
#include " topic_configuration.h"
43
45
#include " configuration.h"
44
46
#include " macros.h"
47
+ #include " config.h"
45
48
46
49
namespace cppkafka {
47
50
@@ -55,6 +58,7 @@ class TopicMetadata;
55
58
class CPPKAFKA_API KafkaHandleBase {
56
59
public:
57
60
using OffsetTuple = std::tuple<int64_t , int64_t >;
61
+ using TopicPartitionsTimestampsMap = std::map<TopicPartition, std::chrono::milliseconds>;
58
62
59
63
virtual ~KafkaHandleBase () = default ;
60
64
KafkaHandleBase (const KafkaHandleBase&) = delete ;
@@ -152,6 +156,19 @@ class CPPKAFKA_API KafkaHandleBase {
152
156
*/
153
157
TopicMetadata get_metadata (const Topic& topic) const ;
154
158
159
+ #ifdef CPPKAFKA_HAVE_OFFSET_FOR_TIMES
160
+
161
+ /* *
162
+ * \brief Gets topic/partition offsets based on timestamps
163
+ *
164
+ * This translates into a call to rd_kafka_offsets_for_times
165
+ *
166
+ * \param queries A map from topic/partition to the timestamp to be used
167
+ */
168
+ TopicPartitionList get_offsets_for_times (const TopicPartitionsTimestampsMap& queries) const ;
169
+
170
+ #endif // CPPKAFKA_HAVE_OFFSET_FOR_TIMES
171
+
155
172
/* *
156
173
* Returns the kafka handle name
157
174
*/
Original file line number Diff line number Diff line change @@ -119,6 +119,23 @@ TopicMetadata KafkaHandleBase::get_metadata(const Topic& topic) const {
119
119
return topics.front ();
120
120
}
121
121
122
+ #ifdef CPPKAFKA_HAVE_OFFSET_FOR_TIMES
123
+ TopicPartitionList
124
+ KafkaHandleBase::get_offsets_for_times (const TopicPartitionsTimestampsMap& queries) const {
125
+ TopicPartitionList topic_partitions;
126
+ for (const auto & query : queries) {
127
+ const TopicPartition& topic_partition = query.first ;
128
+ topic_partitions.emplace_back (topic_partition.get_topic (), topic_partition.get_partition (),
129
+ query.second .count ());
130
+ }
131
+ TopicPartitionsListPtr topic_list_handle = convert (topic_partitions);
132
+ rd_kafka_resp_err_t result = rd_kafka_offsets_for_times (handle_.get (), topic_list_handle.get (),
133
+ timeout_ms_.count ());
134
+ check_error (result);
135
+ return convert (topic_list_handle);
136
+ }
137
+ #endif // CPPKAFKA_HAVE_OFFSET_FOR_TIMES
138
+
122
139
string KafkaHandleBase::get_name () const {
123
140
return rd_kafka_name (handle_.get ());
124
141
}
You can’t perform that action at this time.
0 commit comments