手动确认
此示例说明如何在消费者应用程序中手动确认偏移量。
此示例要求将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();
}
};
}