-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[feat][cpp] Add async receive function to C API #17452
Conversation
7a975c8
to
66765af
Compare
/pulsarbot rerun-failure-checks |
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.
Could you add a basic e2e test for demonstrate it works? I found currently there are nearly no C API related tests. But for new APIs, we should add some tests.
Okay. I'll address it. |
pulsar_message_t *received_msg; | ||
receive_promise.getFuture().get(received_msg); | ||
ASSERT_STREQ(content, static_cast<const char *>(pulsar_message_get_data(received_msg))); | ||
pulsar_message_free(received_msg); |
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 think we should release the received_msg
after the callback
is done. It's better to use pure C semantics here, i.e. use C functions instead of lambda, and do not use pulsar::Promise
, we should define a C struct and pass it to ctx
.
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'll modify it.
However, I also use pulsar::Promise
to wait for the callback completion in the test thread.
To achieve this process, I'll use std::future
instead of conditional wait, etc.
Master Issue: #14452
Motivation
I want to rewrite the pulsar-client-node
receive
method to rely exclusively on async operations rather than worker threads.However, an async receive function is not defined currently in C API.
Modifications
pulsar_consumer_receive_async
andpulsar_receive_callback
to use async receive operation in C APIVerifying this change
(Please pick either of the following options)
This change is already covered by existing tests, such as C tests.
Does this pull request potentially affect one of the following parts:
If
yes
was chosen, please highlight the changespulsar/pulsar-client-cpp/include/pulsar/c/consumer.h
Line 36 in 66765af
pulsar/pulsar-client-cpp/include/pulsar/c/consumer.h
Lines 100 to 108 in 66765af
Documentation
Check the box below or label this PR directly.
Need to update docs?
doc-not-needed