add more tips ops

pull/266/head
Chen Wang 10 years ago
parent 862e23c662
commit 3cc1ad62b6
  1. 32
      examples/tips/client.cc
  2. 3
      examples/tips/client.h
  3. 13
      examples/tips/client_main.cc

@ -36,7 +36,11 @@
#include "examples/tips/client.h" #include "examples/tips/client.h"
using tech::pubsub::Topic; using tech::pubsub::Topic;
using tech::pubsub::DeleteTopicRequest;
using tech::pubsub::GetTopicRequest;
using tech::pubsub::PublisherService; using tech::pubsub::PublisherService;
using tech::pubsub::ListTopicsRequest;
using tech::pubsub::ListTopicsResponse;
namespace grpc { namespace grpc {
namespace examples { namespace examples {
@ -55,6 +59,34 @@ Status Client::CreateTopic(grpc::string topic) {
return stub_->CreateTopic(&context, request, &response); return stub_->CreateTopic(&context, request, &response);
} }
Status Client::ListTopics() {
ListTopicsRequest request;
ListTopicsResponse response;
ClientContext context;
return stub_->ListTopics(&context, request, &response);
}
Status Client::GetTopic(grpc::string topic) {
GetTopicRequest request;
Topic response;
ClientContext context;
request.set_topic(topic);
return stub_->GetTopic(&context, request, &response);
}
Status Client::DeleteTopic(grpc::string topic) {
DeleteTopicRequest request;
proto2::Empty response;
ClientContext context;
request.set_topic(topic);
return stub_->DeleteTopic(&context, request, &response);
}
} // namespace tips } // namespace tips
} // namespace examples } // namespace examples
} // namespace grpc } // namespace grpc

@ -47,6 +47,9 @@ class Client {
public: public:
Client(std::shared_ptr<grpc::ChannelInterface> channel); Client(std::shared_ptr<grpc::ChannelInterface> channel);
Status CreateTopic(grpc::string topic); Status CreateTopic(grpc::string topic);
Status GetTopic(grpc::string topic);
Status DeleteTopic(grpc::string topic);
Status ListTopics();
private: private:
std::unique_ptr<tech::pubsub::PublisherService::Stub> stub_; std::unique_ptr<tech::pubsub::PublisherService::Stub> stub_;

@ -97,8 +97,17 @@ int main(int argc, char** argv) {
creds)); creds));
grpc::examples::tips::Client client(channel); grpc::examples::tips::Client client(channel);
grpc::Status s = client.CreateTopic("test");
gpr_log(GPR_INFO, "return code %d", s.code()); grpc::Status s = client.CreateTopic("/topics/stoked-keyword-656/testtopics");
gpr_log(GPR_INFO, "return code %d, %s", s.code(), s.details().c_str());
GPR_ASSERT(s.IsOk());
s = client.GetTopic("/topics/stoked-keyword-656/testtopics");
gpr_log(GPR_INFO, "return code %d, %s", s.code(), s.details().c_str());
GPR_ASSERT(s.IsOk());
s = client.DeleteTopic("/topics/stoked-keyword-656/testtopics");
gpr_log(GPR_INFO, "return code %d, %s", s.code(), s.details().c_str());
GPR_ASSERT(s.IsOk()); GPR_ASSERT(s.IsOk());
channel.reset(); channel.reset();

Loading…
Cancel
Save