资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

KafkaProducer重试参数retries设置取舍的示例分析

Kafka Producer重试参数retries设置取舍的示例分析,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

站在用户的角度思考问题,与客户深入沟通,找到轵城网站设计与轵城网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站设计、网站建设、企业官网、英文网站、手机端网站、网站推广、申请域名、网页空间、企业邮箱。业务覆盖轵城地区。

1.retries参数说明

参数的设置通常是一种取舍,看下retries参数在版本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.

备注:当发送失败时客户端会进行重试,重试的次数由retries指定,此参数默认设置为0。即:快速失败模式,当发送失败时由客户端来处理后续是否要进行继续发送。如果设置retries大于0而没有设置max.in.flight.requests.per.connection=1则意味着放弃发送消息的顺序性。

2.retries使用建议

使用retries的默认值交给使用方自己去控制,结果往往是不处理。所以通用设置建议设置如下:

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

备注:这样设置后,发送客户端会一直进行重试直到broker返回ack;同时只有一个连接向broker发送数据保证了数据的顺序性。在Leader选举、集群中一个broker挂掉时,发送端会一直重试直到Leader选举结束。避免由于客户端对异常未处理造成的数据丢失,例如:遇到类似“This server is not the leader for that topic-partition”会自动恢复。

3.retries后续发展

该参数的设置已经在kafka 2.4版本中默认设置为Integer.MAX_VALUE;同时增加了delivery.timeout.ms的参数设置。

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

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。


名称栏目:KafkaProducer重试参数retries设置取舍的示例分析
链接URL:http://cdkjz.cn/article/pdeigo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220