springcloudStream集成Kafka遇到的问题
最近做kafka存储文件类型的信息的项目,遇到两个问题一个是springcloudstream的版本问题,这个问题只需要注意在引入maven依赖的时候不添加version就可以避免,把版本管理问题交给
springcloud来管理,比如我用的是--<spring.cloud.version>Hoxton.SR12</spring.cloud.version>
<spring.cloud.alibaba.version>2.2.7.RELEASE</spring.cloud.alibaba.version>。
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-stream-binder-kafka</artifactId> </dependency>
引入依赖之后就需要配置配置文件:
spring.cloud==这里省去上两层 stream: kafka: binder: producerProperties: max: request: size: 209715200 brokers: 127.0.0.1:9092 auto-create-topics: true bindings: input-in-0: destination: testquickstart group: myinput1 output: destination: testquickstart consu-in-0: destination: testquickstart2 group: consu echo-in-0: destination: testquickstart group: echo echo-out-0: destination: testquickstart2 function: definition: echo;input;consu
这里遇到一个
---大文件报错:
org.apache.kafka.common.errors.RecordTooLargeException: The message is 17108616 bytes when serialized which is larger than 1048576, which is the value of the max.request.size configuration.
实际就是添加上下面的配置就可以了。
producerProperties:
max:
request:
size: 209715200
在kafka中存放文件类型的消息,是将文件二进制流进行base64编码,来传送的。
kafka服务端也需要修改---如果要修改服务端配置,则需要修改两个地方,首先是server.properties,加入
message.max.bytes=
209715200
然后是producer.properties,加入
max.request.size=
209715200
同时,消费端也要配置属性max.partition.fetch.bytes以接收大数据。
-----------------------------------------------------------------------
--prducer:
# the maximum size of a request in bytes
max.request.size=524288000
--server
message.max.bytes=629145600
--cosumer
fetch.max.bytes=734003200
参见spring官网。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了