Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. #include <grpc++/grpc++.h>
  5.  
  6. #include "google/pubsub/v1/pubsub.grpc.pb.h"
  7.  
  8. auto main() -> int {
  9.     using grpc::ClientContext;
  10.     using google::pubsub::v1::Subscriber;
  11.     using google::pubsub::v1::PullRequest;
  12.     using google::pubsub::v1::PullResponse;
  13.  
  14.     auto creds = grpc::GoogleDefaultCredentials();
  15.     auto stub = std::make_unique<Subscriber::Stub>(grpc::CreateChannel("pubsub.googleapis.com", creds));
  16.  
  17.     PullRequest request;
  18.     auto const subscription_string = "projects/pubsub-cpp-api-1504713535863/subscriptions/testing";
  19.     request.set_subscription(subscription_string);
  20.     request.set_max_messages(50);
  21.     request.set_return_immediately(false);
  22.  
  23.     PullResponse response;
  24.     ClientContext ctx;
  25.  
  26.     auto status = stub->Pull(&ctx, request, &response);
  27.     if (!status.ok()) {
  28.         // ...
  29.     }
  30.  
  31.     // Do something with "response".
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement