2016-05-17 33 views
1

我正在寫一個簡單的代碼在Python 2.7中消耗apache kafka主題的消息。代碼如下:kafka-python raise kafka.errors.ConsumerFetchSizeTooSmall

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)?

回答

0

我找到了一個解決方案, 使用SimpleConsumer中的參數max_buffer_size

工作代碼爲:

#the size is adherent with my need but is totally arbitrary 
cons = SimpleConsumer(client, group, "my_topic",max_buffer_size=9932768) 
相關問題