kafka python提升kafka.errors.consumerfetchsizetoosmall

bweufnob  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(276)

我正在用python2.7编写一个简单的代码,它使用apachekafka主题的消息传递。代码如下:

from kafka import SimpleConsumer,KafkaClient
group = "my_group_test"
client = KafkaClient('localhost:9092')
cons = SimpleConsumer(client, group, "my_topic")
messages = cons.get_messages(count=1000,block=False)

但提出了一个例外:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/kafka/consumer/simple.py", line 285, in get_messages
    update_offset=False)
  File "/usr/local/lib/python2.7/dist-packages/kafka/consumer/simple.py", line 320, in _get_message
    self._fetch()
  File "/usr/local/lib/python2.7/dist-packages/kafka/consumer/simple.py", line 425, in _fetch
    raise ConsumerFetchSizeTooSmall()
kafka.errors.ConsumerFetchSizeTooSmall

如何修改此参数(consumerfetchsize)以使此代码正常工作?

vd8tlhqk

vd8tlhqk1#

我找到了一个解决方案,在simpleconsumer中使用参数max\u buffer\u size。
工作代码为:


# the size is adherent with my need but is totally arbitrary

cons = SimpleConsumer(client, group, "my_topic",max_buffer_size=9932768)

相关问题