-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Milestone
Description
Affects Version(s): latest
When max retries is reached, the DefaultAfterRollbackProcessor uses seek to skip the failing record. This means that the record will be processed when the app is restarted.
To work around this I extended the DeadLetterPublishingRecoverer to also commit the offset.
Alternatively the DefaultAfterRollbackProcessor could be configured to commit the offsets after rolling back the main transaction.
@Transactional(KAFKA_TRANSACTION_MANAGER)
class OffsetCommittingAndDeadLetterPublishingRecoverer(val template: KafkaTemplate<Any, Any>) :
DeadLetterPublishingRecoverer(template) {
override fun accept(record: ConsumerRecord<*, *>, exception: Exception) {
super.accept(record, exception)
val topicPartition = TopicPartition(record.topic(), record.partition())
val offsetAndMetadata = OffsetAndMetadata(record.offset() +1)
template.sendOffsetsToTransaction(
mapOf(topicPartition to offsetAndMetadata)
)
}
}