简体   繁体   中英

Kafka Spring: How to hide logs from RetryTopicConfigurer

I have a topic with two partitions,i'm using @RetryableTopic and i can see logs on my app console that INFO oskr.RetryTopicConfigurer - Received message in dlt listener: {topic name with second partition} and this is wrong because it's just another partition not dlt topic, how can i hide those logs or avoid them?

 @RetryableTopic(
            attempts = "1",
            backoff = @Backoff(delay = 100, multiplier = 3.0),
            autoCreateTopics = "false",
            topicSuffixingStrategy = TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE, numPartitions = "2")
  @KafkaListener(id= "ccn2_listener",topics = "test", groupId = "test", autoStartup = "${listen.auto.start:true}", topicPartitions =  { @TopicPartition(topic = "ccn2-bam-raw-data", partitions = {"1"})})
public void listen(ConsumerRecord<String, String> consumerRecord, Acknowledgment acknowledgment) throws IOException, InterruptedException {
    log.info(consumerRecord.key());
    log.info(consumerRecord.value());
    {some working with code}
    if(some objectives) {
          throw new RodaTableMappingException("Problem with mapping Kafka record, sending it on dlt topic");

application properties file:

elastic.apm.enabled=true
elastic.apm.server-url=url
elastic.apm.service-name=name
elastic.apm.secret-token=token
elastic.apm.environment=prod
elastic.apm.application-packages=package
elastic.apm.log-level=INFO
apminsight.console.logger=true

And i can see logs like that in my console: 2023-01-24 02:16:08,824 [topic_listener-dlt-0-C-1] INFO
oskr.RetryTopicConfigurer - Received message in dlt listener: topic- 1@38262. And I'm running two instances of this app with different partitions 0 and 1, but same group and topic. And i understand that these logs are because message is received on another partition, but how to avoid them logs

attempts="1" means send it directly to DLT after an initial delivery fails, so it makes no sense to have a back off (or a suffixing strategy).

Using @RetryableTopic is overkill for that use case, a simple dead letter publishing recoverer will suffice.

This works as expected for me...

@SpringBootApplication
public class So75135382Application {

    public static void main(String[] args) {
        SpringApplication.run(So75135382Application.class, args);
    }

    @RetryableTopic(attempts = "1",
            topicSuffixingStrategy = TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE)
    @KafkaListener(id = "so75135382", topics = "so75135382")
    void listen(String in) {
        throw new RuntimeException("test");
    }

    @Bean
    NewTopic topic() {
        return TopicBuilder.name("so75135382").partitions(1).replicas(1).build();
    }

    @Bean
    ApplicationRunner runner(KafkaTemplate<String, String> template) {
        return args -> {
            template.send("so75135382", "foo");
        };
    }

}
Received message in dlt listener: so75135382-dlt-0@3

If you can't figure it out, post a similar, complete, minimal example that exhibits the behavior, so we can see what's wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM