kafka消费/发送消息,消息过大报错解决whose size is larger than the fetch size 1048576

目录

一、kafka消费报错原因

  • 问题原因一:个是kafka本身的配置没有调整到上限

  • 问题原因二:就是我们自己写python消费kafka代码的时候没有参数配置没有限制

  • RecordTooLargeError: ("There are some messages at [Partition=Offset]: {TopicPartition(topic='psadad', partition=1): 75} whose size is larger than the fetch size 1048576 and hence cannot be ever returned. Increase the fetch size, or decrease the maximum message size the broker will allow.", {TopicPartition(topic='psadad', partition=1): 75})

二、解决方案

1、原因一的解决方案
  • 在kafka中,默认的消息体大小为1M。在实际的业务场景,有时候需要修改kafka消息体大小,修改kafka消息体大小需要注意下面的几个方面
    • message.max.bytes (broker配置)
    • replica.fetch.max.bytes (partition配置)
    • max.message.bytes (topic配置)
  • 在生产者端配置max.request.size,这是单个消息最大字节数,根据实际调整,max.request.size 必须小于 message.max.bytes 以及消费者的 max.partition.fetch.bytes。这样消息就能不断发送
  • kafka config服务端配置文件server.properties, server.properties中加上的message.max.bytes配置
2、原因二的解决方案
  • 如图添加参数max_partition_fetch_bytes=1048576 * 10

相关推荐
“AI国潮设计-小江”几秒前
【SDXL实战】Python自动化生成3D潮汕美食IP,附ComfyUI工作流与商用变现思路
开发语言·人工智能·python·prompt·aigc
tellmewhoisi5 分钟前
python的鬼畜写法(从js角度看)
python
夜雪一千25 分钟前
如何使用Python的BeautifulSoup库来处理HTML
python
傻啦嘿哟26 分钟前
某新闻平台爬虫:爬取各频道新闻,分析媒体传播规律
python
szephyr27 分钟前
消息队列入门:RabbitMQ 和 Kafka 到底怎么选,什么时候不该用
后端·架构·kafka·消息队列·rabbitmq
鹿角片ljp33 分钟前
Prompt Cache、Token 成本与 Plan Compiler 的工程设计
java·python·算法
麻雀飞吧9 小时前
先判断工具用来学习、开发还是执行
人工智能·python
人邮异步社区9 小时前
学习Python的最佳学习路径是什么?
python·程序员
troy12812 小时前
Python 基础语法(九):Django/Flask/FastAPI 三大 Web 框架详细对比解析
python·jupyter·django·flask·github·fastapi
jzshmyt12 小时前
我用 Python 从零“生成“了一个宇宙,然后让它观察自己(v14)
人工智能·pytorch·python·numpy·matplotlib·空间计算·scipy