[英]Error handling in Spring Cloud Stream Kafka in Batch mode
[英]spring kafka cloud stream: limit retry attempts in batch mode
當在使用消息 spring 時拋出異常時,嘗試不斷讀取相同的消息並且其他消息的使用基本停止。 我試過像這樣設置defaultRetryable和retryableExceptions屬性:
spring:
cloud.stream:
bindings:
consumer-in-0:
consumer:
defaultRetryable: false
retryable-exceptions:
org.springframework.dao.DataIntegrityViolationException: false
但它沒有效果,我怎樣才能禁止重復閱讀失敗消息的嘗試或限制此類嘗試的次數?
更新
查看 spring 源KafkaMessageChannelBinder
:
protected MessageProducer createConsumerEndpoint() {
// ...
if (!extendedConsumerProperties.isBatchMode()
&& extendedConsumerProperties.getMaxAttempts() > 1
&& transMan == null) {
kafkaMessageDrivenChannelAdapter
.setRetryTemplate(buildRetryTemplate(extendedConsumerProperties));
所以看起來提到的屬性只有在不使用批處理模式時才有效,這是我的情況(batch==true)。 想知道如何在批處理模式下處理重試嗎?
默認情況下,批處理偵聽器永遠重試,因為框架無法判斷批處理中的哪條記錄失敗。
最好在偵聽器本身中以批處理模式處理錯誤。
您可以添加一個ListenerContainerCustomizer
bean 來配置不同的BatchErrorHandler
。 有關選項,請參閱https://docs.spring.io/spring-kafka/docs/current/reference/html/#annotation-error-handling 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.