溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Kafka Producer重試參數(shù)retries設(shè)置取舍的示例分析

發(fā)布時(shí)間:2021-11-17 17:18:20 來源:億速云 閱讀:686 作者:柒染 欄目:大數(shù)據(jù)

Kafka Producer重試參數(shù)retries設(shè)置取舍的示例分析,很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

1.retries參數(shù)說明

參數(shù)的設(shè)置通常是一種取舍,看下retries參數(shù)在版本0.11.3說明:

Setting a value greater than zero will cause the client to resend
any record whose send fails with a potentially transient error.
Note that this retry is no different than if the client resent the
record upon receiving the error.
Allowing retries without setting max.in.flight.requests.per.connection to 1 will potentially change
the ordering of records because if two batches are sent to a single
partition, and the first fails and is retried but the second succeeds,
then the records in the second batch may appear first.

備注:當(dāng)發(fā)送失敗時(shí)客戶端會(huì)進(jìn)行重試,重試的次數(shù)由retries指定,此參數(shù)默認(rèn)設(shè)置為0。即:快速失敗模式,當(dāng)發(fā)送失敗時(shí)由客戶端來處理后續(xù)是否要進(jìn)行繼續(xù)發(fā)送。如果設(shè)置retries大于0而沒有設(shè)置max.in.flight.requests.per.connection=1則意味著放棄發(fā)送消息的順序性。

2.retries使用建議

使用retries的默認(rèn)值交給使用方自己去控制,結(jié)果往往是不處理。所以通用設(shè)置建議設(shè)置如下:

retries = Integer.MAX_VALUE
max.in.flight.requests.per.connection = 1

備注:這樣設(shè)置后,發(fā)送客戶端會(huì)一直進(jìn)行重試直到broker返回ack;同時(shí)只有一個(gè)連接向broker發(fā)送數(shù)據(jù)保證了數(shù)據(jù)的順序性。在Leader選舉、集群中一個(gè)broker掛掉時(shí),發(fā)送端會(huì)一直重試直到Leader選舉結(jié)束。避免由于客戶端對(duì)異常未處理造成的數(shù)據(jù)丟失,例如:遇到類似“This server is not the leader for that topic-partition”會(huì)自動(dòng)恢復(fù)。

3.retries后續(xù)發(fā)展

該參數(shù)的設(shè)置已經(jīng)在kafka 2.4版本中默認(rèn)設(shè)置為Integer.MAX_VALUE;同時(shí)增加了delivery.timeout.ms的參數(shù)設(shè)置。

The default value for the producer's retries config was changed to
Integer.MAX_VALUE, as we introduced delivery.timeout.ms in KIP-91,
which sets an upper bound on the total time between sending a
record and receiving acknowledgement from the broker.
By default, the delivery timeout is set to 2 minutes.

KIP-91: https://cwiki.apache.org/confluence/display/KAFKA/KIP-91+Provide+Intuitive+User+Timeouts+in+The+Producer

看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝您對(duì)億速云的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI