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

相关推荐
starzy19901 小时前
深入理解Scala隐式参数:上下文流转
开发语言·python·scala
wuyk5552 小时前
Spider-第16讲-线程池与竞态问题
大数据·爬虫·python·elasticsearch·搜索引擎
goehou7 小时前
Kafka 的默认配置适合演示,不适合生产
kafka·消息队列·幂等·ai agent
kyle~8 小时前
FastAPI --- 将业务能力以 API 的形式提供给外部系统
python·fastapi·前后端
aiotto资源分享9 小时前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
梯度下降者10 小时前
Python信号量,条件变量,事件学习
python·条件变量·事件·信号量·线程通信
MSTcheng.10 小时前
【AI应用实战】用 FastAPI + SSE 做一个自己的 AI 聊天网页:流式输出、多轮对话与完整源码
人工智能·python·大模型·fastapi·sse·ai聊天助手
the局外人11 小时前
Python 实战检索优化:BM25、向量与重排
数据库·后端·python
__underline__11 小时前
冷门Python知识点006篇:Python 类体里的名字,能被"凭空造出来"
后端·python
ClouGence12 小时前
开源数据库管理工具 CloudDM 发布新版本,支持 GreptimeDB 数据源
数据库·kafka