h-j-13 opened a new issue #8869:
URL: https://github.com/apache/pulsar/issues/8869
I want use `consumer.receiveAsync()` to receive a single message from topic.
but i don't know how to confirm message properly, because the `receiveAsync()`
callback function don't provide a consumer as args.
```cpp
// >>> lib/Consumer.cc#receiveAsync
void Consumer::receiveAsync(ReceiveCallback callback) {
if (!impl_) {
Message msg;
callback(ResultConsumerNotInitialized, msg);
return;
}
impl_->receiveAsync(callback);
}
// callback function
// >>> include/pulsar/ConsumerConfiguration.h#ReceiveCallback
typedef std::function<void(Result, const Message& msg)> ReceiveCallback;
```
OR the message has already been confirmed before callback function called?
My Demo. i don't know how to properly confirm message. confused.
```cpp
#include <iostream>
#include <pulsar/Client.h>
#include <lib/LogUtils.h>
DECLARE_LOG_OBJECT()
using namespace pulsar;
using namespace std;
void callback(Result code, const Message& msg) {
cout << "Received code: " << code << "Msg Length" << msg.getLength() <<
endl;
// consumer.acknowledge(); ?
}
int main() {
cout << "Sync Consumer Test | pulsar://100.76.43.216:6650" << endl;
Client client("pulsar://localhost:6650");
Consumer consumer;
Consumer consumer2;
Consumer consumer3;
ConsumerConfiguration config;
config.setConsumerType(ConsumerShared);
Result result =
client.subscribe("persistent://HJ13/Test/performance_test",
"consumerRecvAsync", config, consumer);
if (result != ResultOk) {
LOG_ERROR("Failed to subscribe: " << result);
return -1;
}
consumer.receiveAsync(callback);
// consumer.acknowledge(); ?
// Wait
int n;
std::cin >> n;
client.close();
}
```
I want confirm message like
`pulsar-client-cpp/examples/SampleConsumerListener.cc`
```cpp
...
void listener(Consumer consumer, const Message& msg) {
LOG_INFO("Got message " << msg << " with content '" <<
msg.getDataAsString() << "'");
consumer.acknowledge(msg.getMessageId());
}
...
```
https://github.com/apache/pulsar/blob/master/pulsar-client-cpp/examples/SampleConsumerListener.cc#L32
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]