How to write Kafka consumers - single threaded vs multi threaded

前端 未结 2 1825
忘了有多久
忘了有多久 2021-01-01 18:51

I have written a single Kafka consumer (using Spring Kafka), that reads from a single topic and is a part of a consumer group. Once a message is consumed, it will perform al

相关标签:
2条回答
  • 2021-01-01 19:23

    Your existing solution is best. Handing off to another thread will cause problems with offset management. Spring kafka allows you to run multiple threads in each instance, as long as you have enough partitions.

    0 讨论(0)
  • 2021-01-01 19:29

    If your current approach works, just stick to it. It's the simple and elegant way to go.

    You would only go to approach 2 in case you cannot for some reason increase the number of partitions but need higher level of parallelism. But then you have ordering and race conditions to worry about. If you ever need to go that route, I'd recommend the akka-stream-kafka library, which provides facilities to handle offset commits correctly and to do what you need in parallel and then merge back into a single stream preserving the original ordering, etc. Otherwise, these things are error-prone to do yourself.

    0 讨论(0)
提交回复
热议问题