Search code examples
javaapache-kafkaspring-kafka

Two consumers with non-blocking retry listening to one kafka topic


I use spring kafka 2.8.8. I have two consumers which use @RetryableTopic annotation for non-blocking retries. Both of them listen the same topic and they have separate consumer groups.

Implementation of the first consumer:

@KafkaListener(
    topics = "topic",
    containerFactory = "containerFactory-one",
    groupId = "group-one"
)
@RetryableTopic(
    attempts = "3",
    backoff = @Backoff(delay = 30000,
        multiplierExpression = 2.0 , maxDelay = 600000),
    listenerContainerFactory = "containerFactory-one",
    kafkaTemplate = "template-one",
    retryTopicSuffix = "-one-retry",
    dltTopicSuffix = "-one-dlt",
    topicSuffixingStrategy = TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE
)

Implementation of the second consumer:

@KafkaListener(
    topics = "topic",
    containerFactory = "containerFactory-two",
    groupId = "group-two"
)
@RetryableTopic(
    attempts = "3",
    backoff = @Backoff(delay = 30000,
        multiplierExpression = 2.0 , maxDelay = 600000),
    listenerContainerFactory = "containerFactory-two",
    kafkaTemplate = "template-two",
    retryTopicSuffix = "-two-retry",
    dltTopicSuffix = "-two-dlt",
    topicSuffixingStrategy = TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE
)

So in total I have one main topic and 3 retry topics for each consumer. Each retry topic has own consumer group.

PROBLEM: When the first consumer fails, then the retry message is sent and it is read by the second consumer retry-0. Is it a bug or did I make here some configuration mistake?


SOLUTION: This issue was already raised here: https://github.com/spring-projects/spring-kafka/issues/2282

It was solved in 3.0.0.


Solution

  • SOLUTION: This issue was already raised here: https://github.com/spring-projects/spring-kafka/issues/2282

    https://docs.spring.io/spring-kafka/docs/3.0.5/reference/html/#retry-config

    It was solved in 3.0.0.