Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .offsetsForTimes of the consumer API #40

Open
raycheung opened this issue Jan 8, 2019 · 0 comments
Open

Support .offsetsForTimes of the consumer API #40

raycheung opened this issue Jan 8, 2019 · 0 comments

Comments

@raycheung
Copy link
Contributor

Currently I'm doing something like below in order to lookup offsets at a certain timestamps then reset the topic/partition to that. I've to go through a few Java/Clojure interop in order to match with the API interface. It would be great if all can be done nicely in Clojure.

(require '[kinsky.client :as k])

(let [topic-partitions~
      (map k/->topic-partition [{:topic "topic" :partition 0} {:topic "topic" :partition 1}])

      topic-partition-times-map~
      (into {} (for [tp topic-partitions] [tp timestamp]))

      topic-partition-offsets-map
      (.offsetsForTimes @consumer topic-partition-times-map (t/duration 10 :seconds))

      topic-offsets
      (for [[topic-partition offset-and-timestamp] topic-partition-offsets-map
            :when (not (nil? offset-and-timestamp))]
        (merge (k/topic-partition->data topic-partition) {:offset (.offset offset-and-timestamp)}))]
  (k/commit! consumer topic-offsets)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant