Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to close async producer #291

Closed
darionyaphet opened this issue Jan 12, 2015 · 3 comments
Closed

how to close async producer #291

darionyaphet opened this issue Jan 12, 2015 · 3 comments

Comments

@darionyaphet
Copy link

Hi
I write a simple sender script reading a file and send to kafka 0.8.1 line by line when it is send to EOF but can't exit ! Actually this script is hang on ..

producer = SimpleProducer(client, async=True,
                          req_acks=SimpleProducer.ACK_AFTER_LOCAL_WRITE,
                          ack_timeout=2000,
                          batch_send=True)

for line in open(file_name,'r').readlines():
    producer.send_messages("topic.default.2",line)

producer.stop()
client.close()

Somebody could help me ? thanks a lot ~

@dpkp dpkp added the question label Jan 13, 2015
@dpkp dpkp changed the title how to close producer how to close async producer Jan 13, 2015
@jswetzen
Copy link

jswetzen commented Mar 3, 2015

I had a similar problem, in my case I couldn't make the script stop on KeyboardInterrupt.
In the end I just batched the messages manually by putting them in a list and sending them as keyword arguments. In your case it would be something like

lines = []

with open(file_name, 'r') as f:
    for line in f:
        lines.append(line)
        if len(lines) >= batch_size:
            producer.send_messages("topic", *lines)
            lines = []

It feels bad that I'm not using the batch functionality that's available, but I get twice the speed of using batch_send=True and the messages seem to be coming through all right.

@dpkp dpkp added the producer label Mar 30, 2015
@dpkp dpkp added this to the 0.9.4 Release milestone Mar 30, 2015
@dpkp
Copy link
Owner

dpkp commented Mar 30, 2015

async producer code has been buggy, but we're hoping to clean it up for the next release. will update w/ results.

@dpkp
Copy link
Owner

dpkp commented Jun 7, 2015

fixes to async producer in #331 and #388 should make producer.stop() more reliable. You can also tune how long the producer will continue attempting to send queued messages after receiving the stop signal via async_stop_timeout

@dpkp dpkp closed this as completed Jun 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants