Skip to content

Option to commit offsets when publishing to dead letter topic. #990

@miklesw

Description

@miklesw

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.

https://stackoverflow.com/questions/55023117/kafkatemplate-in-transactional-kafkalistener-publishes-messages-when-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)
            )
        }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions