英文:
What is the default kafka ack policy for @KafkaListener?
问题
-
"log.info("new message from kafka topic received: {}", message);" 被调用之前,将会发送 ack 吗?
-
如果第一个问题的答案是 "No",即使发生异常,ack 会被发送吗?
英文:
Let's say I have such a listener and no custom kafka configuration:
@KafkaListener(topics = "${my_topic_listen}", autoStartup = "true")
public void listenForMessage(String message) {
log.info("new message from kafka topic received: {}", message);
if(message.length() >1000) {
throw new RuntimeException("TooLongMessage");
}
log.info(message is checked);
}
-
Will ack be sent before
log.info("new message from kafka topic received: {}", message);
is called ?
- if answer for the first question is "No". Will be ack sent even in case of exception ?
答案1
得分: 1
会在发生异常的情况下发送ack吗?
这取决于错误处理程序。
默认情况下,引发异常的记录将在记录和确认之前重试最多9次。您可以配置重试行为,并添加自定义恢复操作,以在重试用尽时采取一些措施(或使用提供的DeadLetterPublishingRecoverer
)。您还可以配置哪些异常可以重试,哪些不能。
请参阅https://docs.spring.io/spring-kafka/docs/current/reference/html/#annotation-error-handling
英文:
>Will be ack sent even in case of exception ?
It depends on the error handler.
By default, the record causing the exception will be retried up to 9 times before being logged and ack'd. You can configure the retry behavior, and add a custom recover to take some action when retries are exhausted (or use the provided DeadLetterPublishingRecoverer
. You can also configure which exceptions are retryable, and which are not.
See https://docs.spring.io/spring-kafka/docs/current/reference/html/#annotation-error-handling
答案2
得分: 0
根据这里提到的信息,仅在消息被消费者消耗后,确认将发送给代理。<br>
- 仅在listenForMessage方法完全执行后,将发送确认。
<br> - 由于异常与工作环境的故障无关,Kafka消费者将消息标记为已消耗并将确认发送给代理。
英文:
As mentioned here, the ack will be sent to the broker only after the message is consumed by the consumer. <br>
- Ack will be sent after the listenForMessage method is completely executed.
<br> - Since the exception is not related to the failure of working environment, the kafka consumer marks the message as consumed and sends the ACK to the broker.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论