手动确认
此示例演示了如何在消费者应用程序中手动确认偏移量。
此示例要求将 spring.cloud.stream.kafka.bindings.input.consumer.ackMode
设置为 MANUAL
。对示例使用相应的输入通道名称。
@SpringBootApplication
public class ManuallyAcknowdledgingConsumer {
public static void main(String[] args) {
SpringApplication.run(ManuallyAcknowdledgingConsumer.class, args);
}
@Bean
public Consumer<Message<?>> process() {
return message -> {
Acknowledgment acknowledgment = message.getHeaders().get(KafkaHeaders.ACKNOWLEDGMENT, Acknowledgment.class);
if (acknowledgment != null) {
System.out.println("Acknowledgment provided");
acknowledgment.acknowledge();
}
};
}