kafka消息发送大小限制 python confluent_kafka客户端

在使用Python的confluent_kafka客户端发送base64编码的图片时,遇到KafkaBroker的消息大小限制问题,导致KafkaError:Messagesizetoolarge错误。为解决此问题,已在客户端配置中增加了message.max.bytes参数,将其设置为200000000字节以扩大消息大小限制。
摘要由CSDN通过智能技术生成

kafka消息发送大小限制 python confluent_kafka客户端

kafka的broker限制调整过后,发送图片base64编码,出现下面的问题

此处有关于kafka配置的参数说明:

librdkafka/CONFIGURATION.md at master · confluentinc/librdkafka · GitHub

图片上传错误,报出:

cimpl.KafkaException: KafkaError{code=MSG_SIZE_TOO_LARGE,val=10,str="Unable to produce message: Broker: Message size too large"}

的错误。

在客户端增加一个配置:

'message.max.bytes': 200000000

        p = Producer({'bootstrap.servers': self.kafkaUrl,
                      'message.max.bytes': 200000000})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Confluent Kafka is a Python client library for Apache Kafka, developed by Confluent. It provides an easy-to-use interface for interacting with Kafka clusters, allowing you to produce and consume messages from Kafka. To use the confluent_kafka library in, you first need to install it. You can do this by running the following command: ``` pip install confluent-kafka ``` Once installed, you can import the library in your Python code as follows: ```python from confluent_kafka import Producer, Consumer ``` To produce messages to a Kafka topic, you can create a `Producer` instance and use its `produce()` method. Here's an example: ```python producer = Producer({'bootstrap.servers': 'localhost:9092'}) topic = 'my_topic' message = 'Hello, Kafka!' producer.produce(topic, message.encode('utf-8')) producer.flush() ``` To consume messages from a Kafka topic, you can create a `Consumer` instance and use its `subscribe()` and `poll()` methods. Here's an example: ```python consumer = Consumer({ 'bootstrap.servers': 'localhost:9092', 'group.id': 'my_consumer_group', 'auto.offset.reset': 'earliest' }) topic = 'my_topic' consumer.subscribe([topic]) while True: msg = consumer.poll(1.0) if msg is None: continue if msg.error(): print(f"Consumer error: {msg.error()}") continue print(f"Received message: {msg.value().decode('utf-8')}") consumer.close() ``` These are just basic examples to get you started with the confluent_kafka library. You can refer to the official documentation for more advanced usage and configuration options. Please note that you need a running Kafka cluster to use the confluent_kafka library.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值