Fork me on GitHub
#jackdaw
<
2019-05-21
>
dharrigan11:05:42

I'm wondering (new to the library), if I wanted simply to consume messages from a kafka topic and invoke a function, passing in each message, without any further action (no sending on to other topics), which jackdaw API would suit? Sort of like a peek, but a do 🙂 Foreach?

cddr11:05:53

Hey @dharrigan, Thanks for trying it out. The jackdaw.client.log/log function gives you a lazy seq of "datafied" consumer records. So e.g. something like this...

(with-open [consumer (-> (jackdaw.client/consumer consumer-config)
                         (jackdaw.client/subscribe topic-config))]
  (doseq [elem (jackdaw.client.log/log consumer 1000)]
     (do-it elem)))

dharrigan11:05:11

You're welcome, thanks for providing a nice library! So, I can call (client/log 1000 my-function) and my-function would receive a message (if there are ones to consume of course)

dharrigan11:05:59

thanks for the code snippet! Very handy! 🙂

cddr11:05:19

The devil is in the details though. Once you start breaking your topic up into partitions, and having opinions about what should happen when things fail, get re-started, etc, then kafka streams has support for implementing the desired behavior.

dharrigan11:05:55

Thanks again 🙂 Very useful - just starting small and working up to it. Thanks for your time.

👍 4
dharrigan13:05:19

@cddr Thank you for the help previously, I got my client to work successfully now! Have a nice afternoon!