Spring Boot Kafka with MANUAL_IMMEDIATE ack

Viewed 3329

I have a Springboot app. wiuth this configuration:

  kafka:
    consumer:
      listener:
        ack-mode: MANUAL_IMMEDIATE

ad this consumer:

@KafkaListener(topics = "test", groupId = "group_id")
    public void consume(String message, Acknowledgment ack) throws IOException {
            ack.acknowledge();
    }

but I have this error when receiving a message:

org.springframework.messaging.converter.MessageConversionException: Cannot convert from [java.lang.String] to [org.springframework.kafka.support.Acknowledgment] for GenericMessage 
1 Answers

It appears that your YAML is not being read; I just tested it

CORRECTION

You have invalid YAML - remove the consumer element.

spring:
  kafka:
    consumer:
      auto-offset-reset: earliest
    listener:
      ack-mode: MANUAL_IMMEDIATE

And it worked fine; removing the ack-mode gives me the same error that you see.

@SpringBootApplication
public class So60929385Application {

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

    @KafkaListener(id = "so60929385", topics = "so60929385")
    public void listen(String in, Acknowledgment ack) {
        System.out.println(in);
        ack.acknowledge();
    }

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

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