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官网。

浙公网安备 33010602011771号