-
Notifications
You must be signed in to change notification settings - Fork 73
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
Implement async confluent-kafka producer #775
Conversation
a5e4bbe
to
7e6d22f
Compare
4740bab
to
0112a8c
Compare
56642a0
to
cdd9907
Compare
0112a8c
to
981fa69
Compare
cdd9907
to
3a2fa65
Compare
981fa69
to
0039127
Compare
f112c8f
to
334035e
Compare
0039127
to
f86d68d
Compare
334035e
to
f5e9ef3
Compare
096fda4
to
8eeade1
Compare
8e0f0d4
to
e91aafa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel confident in merging once you reply to my doubts :)
Just to make sure this doesn't become a future blocker, it could perhaps be worth experimenting with handling SSL external to confluent-kafka, and making it communicate through an already setup TLS connection. |
3a3f265
to
5787118
Compare
89db3f9
to
19d8b16
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I added a nit-level comment, but I think this is mergable as-is. Nice work!
THe async `AIOKafkaProducer` is implemented as a wrapper around `KafkaProducer` with an async `send` method and a poll-thread to continuously send messages in the background, making the result of `send` an awaitable `asyncio.Future`. The example of confluent-kafka has been followed: https://github.com/confluentinc/confluent-kafka-python/blob/master/examples/asyncio_example.py
REST webapp improvement: Using `on_cleanup` is not the correct hook to use here, as this would run _after_ the event loop has closed, making it unsuitable for cancelling background tasks for example. `on_shutdown` is triggered before the REST app shuts down, thus it's able to clean up eg. Kafka clients, background tasks, etc. properly. Before this change, the symptom of the bug is most prevalent in the Karapace REST proxy and its "idle proxy janitor" background task. Stopping the application when the janitor task is not running is straightforward, however when any `UserRestProxy` is present (ie. some requests have already been handled) and the task is running, stopping the REST proxy hangs or needs multiple signals to shut down. With the new `AIOKafkaProducer` implementation (which runs a poll-thread in the background) this results in an application that is unable to gracefully shutdown, only SIGKILL works. Using the `on_shutdown` hook fixes this issue, as we still have an event loop available to be able to cancel background tasks, etc.
19d8b16
to
a51027d
Compare
About this change - What it does
KafkaProducer
with an asyncsend
method and a poll-thread to send messages continuously in the backgroundon_cleanup
toon_shutdown
- this was an existing bug preventing any kind of closing of resources (Kafka clients, consumer manager, etc.) to actually run, further explanation in commit messageWhy this way