SpringBoot-Kafka-监听-禁止自启动问题

参考链接:SpringBoot - Kafka的集成与使用详解12(消费者7:动态开启、关闭监听)

报错:org.springframework.kafka.listener.ListenerExecutionFailedException: invokeHandler Failed ; nested exception is java.lang.IllegalStaeException: No Acknowledgment available as an argument, the listener container must have a MANUAL Ackmode to populate the Acknowledgment .; nested exception is java.lang.IllegalStaeException: No Acknowledgment available as an argument, the listener container must have a MANUAL Ackmode to populate the Acknowledgment

翻译:没有可用的确认作为参数,侦听器容器必须具有手动确认模式才能填充确认;没有可用的确认作为参数,侦听器容器必须具有手动确认模式才能填充确认

报错截图
SpringBoot-Kafka-监听-禁止自启动问题_第1张图片
SpringBoot-Kafka-监听-禁止自启动问题_第2张图片
参考的代码

@Configuration
public class KafkaInitialConfiguration {
 
    // 监听器工厂
    @Autowired
    private ConsumerFactory consumerFactory;
 
    // 监听器容器工厂(设置禁止KafkaListener自启动)
    @Bean
    public ConcurrentKafkaListenerContainerFactory delayContainerFactory() {
        ConcurrentKafkaListenerContainerFactory container =
                new ConcurrentKafkaListenerContainerFactory();
        container.setConsumerFactory(consumerFactory);
        //禁止自动启动
        container.setAutoStartup(false);
        return container;
    }
}
@Component
public class KafkaConsumer {
    // 消费监听
    @KafkaListener(id = "myListener1", topics = {"topic1"},
            containerFactory = "delayContainerFactory")
    public void listen1(String data) {
        System.out.println("监听器收到消息:" + data);
    }
}

试了好几种方式都不行,最后看到注解才发现,已经有字段可以控制了

@KafkaListener
String autoStartup

SpringBoot-Kafka-监听-禁止自启动问题_第3张图片

你可能感兴趣的:(springboot,其他,Java,kafka,java,spring,boot,注解,问题)