franz-go icon indicating copy to clipboard operation
franz-go copied to clipboard

kgo: add examples of commiting mark offsets and consuming with dlq

Open arlanram opened this issue 8 months ago • 8 comments

some examples of commiting mark offsets and consuming with DLQ mechanism

arlanram avatar Apr 17 '25 16:04 arlanram

@twmb please consider looking for this PR, thanks!

arlanram avatar Apr 17 '25 19:04 arlanram

Hi @arlanram , Thanks for this PR. As a user, I would like to clarify a few points:

  • Does the retry() function allow configuring the number of retry attempts?
  • Does using retry() block the queue and delay the processing of other pending events?

In the Baeldung article on Spring Retry Kafka Consumer, it suggests using RetryableTopic as a more optimal solution.

I think it would be worth considering this approach before finalizing the PR

hale249 avatar May 04 '25 16:05 hale249

hi @hale249

  1. yes, it depends on you, you can bind it to your config or external value, this is just for example usage
  2. it does not block or delay, because a new goroutine spawns when retry happens

RetryableTopic it's itself the same mechanism as DLQ.

arlanram avatar May 10 '25 12:05 arlanram

Hi @arlanram, Actually, I'm also quite concerned about the possibility of losing messages when the server goes down while a goroutine is processing a message.

Do you have any additional options to help prevent data loss?

hale249 avatar May 10 '25 16:05 hale249

@hale249

  1. you should manage partition hooks on revoke and lost cases
  2. use graceful handling of records
  3. use external data storages to make sure you can restart a consumer on desired state and be able to prevent duplications

hope it can be useful!

arlanram avatar May 10 '25 17:05 arlanram

Thankiu @arlanram I think it should be handled to minimize message loss during processing. With your logic, if the server is off, the message won't be processed. You should add the solution below for comprehensive handling.

  1. If there's an error, push it to a Kafka error topic, and then a consumer will listen and process it.
  2. If there's an error, push it to Redis/DB, and a cronjob will process it gradually

hale249 avatar May 11 '25 13:05 hale249

@hale249 please make sure that this is just for example usage of DLQ and MarkCommitOffsets. it's not intended to implement full solution. by the way see other examples in directory, hope it will be helpful.

arlanram avatar May 11 '25 14:05 arlanram

hi @twmb , thanks for the comments, fixed them

arlanram avatar May 23 '25 09:05 arlanram

Please add the one comment & squash commits (or at the least, squash commits) -- looks good otherwise, will merge once squashed.

twmb avatar Jun 20 '25 15:06 twmb

@twmb done

arlanram avatar Jun 21 '25 17:06 arlanram