Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <memory>
- #include <grpc++/grpc++.h>
- #include "google/pubsub/v1/pubsub.grpc.pb.h"
- auto main() -> int {
- using grpc::ClientContext;
- using google::pubsub::v1::Subscriber;
- using google::pubsub::v1::PullRequest;
- using google::pubsub::v1::PullResponse;
- auto creds = grpc::GoogleDefaultCredentials();
- auto stub = std::make_unique<Subscriber::Stub>(grpc::CreateChannel("pubsub.googleapis.com", creds));
- PullRequest request;
- auto const subscription_string = "projects/pubsub-cpp-api-1504713535863/subscriptions/testing";
- request.set_subscription(subscription_string);
- request.set_max_messages(50);
- request.set_return_immediately(false);
- PullResponse response;
- ClientContext ctx;
- auto status = stub->Pull(&ctx, request, &response);
- if (!status.ok()) {
- // ...
- }
- // Do something with "response".
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement