问题描述
我正在尝试查找有关通过异步grpc使用Pubsub Streaming API的文档,但找不到任何文档.
I'm trying to find a documentation on using Pubsub Streaming API over async grpc but can't find any.
我有这个简单的代码,可以读取主题中的所有消息:
I have this simple code to read all messages from topic:
auto creds = grpc::GoogleDefaultCredentials();
auto stub = std::make_unique<Subscriber::Stub>(
grpc::CreateChannel("pubsub.googleapis.com", creds));
ClientContext context;
std::unique_ptr<ClientReaderWriter<
StreamingPullRequest, StreamingPullResponse>> stream(
stub->StreamingPull(&context));
StreamingPullRequest request;
request.set_subscription(
"projects/test/subscriptions/test-subscription");
request.set_stream_ack_deadline_seconds(10);
stream->Write(request);
StreamingPullResponse response;
while (stream->Read(&response)) {
StreamingPullRequest ack_request;
for (const auto &message : response.received_messages()) {
ack_request.add_ack_ids(message.ack_id());
}
stream->Write(ack_request);
}
基本上,我想做同样的事情,但是要使用异步rpc调用,因此该代码在回调内部被调用:
Basically I wanna do the same but with async rpc call so this code is called inside of callback:
StreamingPullRequest ack_request;
for (const auto &message : response.received_messages()) {
ack_request.add_ack_ids(message.ack_id());
}
stream->Write(ack_request);
您能帮我举一个简单的异步代码示例吗?
Could you help me with a simple example of async code doing the same?
推荐答案
当前 Google Cloud Platform C ++ Pub/Sub 库尚未由供应商正式宣布,并且没有实现的ETA,因此代码库作为概念验证,但仍没有完整的文档记录,没有适当的用法示例.您可以通过此 Github来跟踪社区为进一步图书馆开发所做的努力线程.
Currently Google Cloud Platform C++ Pub/Sub library has not yet being officially announced by the vendor and there are no ETAs for the implementation, thus the code base exists as a proof of concept and still not fully documented with no decent examples of usage. You can keep track the community efforts for further library development following this Github thread.
据我所知,您正在寻找执行 StreamingPull 的任何见解 gRPC 调用,查看我建议您检查一下他的方法,该方法在概念上适合您的用例.
As far as I see you're looking for any of insights performing StreamingPull via async gRPC call, reviewing the answer being posted by @Manuel Menzella I would recommend to check out his approach that can be conceptually suitable for your use case.
这篇关于C ++中的Google Cloud Pubsub异步流API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!