1
votes

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);
  }

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?

1

1 Answers

0
votes

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.

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.