Skip to content

Is producer.flush() a must? #137

Closed
Closed
@smj19

Description

@smj19

My multi-threaded producer doesn't seem to be sending any messages if flush is NOT included in the end. This is my script:

conf = {'bootstrap.servers': 'localhost:9092', 
             'queue.buffering.max.messages': 1000000, 
             'queue.buffering.max.ms' : 500, 
             'batch.num.messages': 50, 
             'default.topic.config': {'acks': 'all'}}

producer = confluent_kafka.Producer(**conf)

        try:
               
                fh = open(os.path.join("/home/samples/samples", queue.get()), "r")
                while True:
                    data = fh.read(10240)
                    if data == '':
                        fh.close()
                        break
                   try:
                        producer.produce(topic, value=data, callback=self.delivery_callback)
                        producer.poll(0)
                   except BufferError as e:
                        print "Buffer full"
                        producer.produce(topic, value=data, callback=self.delivery_callback)
                        producer.poll(0)
                  #print "Waiting for %d deliveries\n" % len(producer)
                  #producer.flush()
            except IOError as e:
                print "IO error"
            except ValueError:
                print "Conversion error"
            except:
                print "unexpected error"
                raise
            queue.task_done()

Adding flush() increases the run time drastically. Is it a must? Is there any other way I can make sure all the messages have reached the topics?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions