From 04f1aa809a60bda7e64e72863890bba69ac0cfbf Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Fri, 30 Jan 2015 18:26:16 -0800 Subject: Implement both Publisher and Subscriber. --- examples/tips/main.cc | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 examples/tips/main.cc (limited to 'examples/tips/main.cc') diff --git a/examples/tips/main.cc b/examples/tips/main.cc new file mode 100644 index 0000000000..94a0bc7995 --- /dev/null +++ b/examples/tips/main.cc @@ -0,0 +1,145 @@ +/* + * + * Copyright 2014, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "examples/tips/publisher.h" +#include "examples/tips/subscriber.h" +#include "test/cpp/util/create_test_channel.h" + +DEFINE_int32(server_port, 443, "Server port."); +DEFINE_string(server_host, + "pubsub-staging.googleapis.com", "Server host to connect to"); +DEFINE_string(service_account_key_file, "", + "Path to service account json key file."); +DEFINE_string(oauth_scope, + "https://www.googleapis.com/auth/cloud-platform", + "Scope for OAuth tokens."); + +namespace { + +const char kTopic[] = "/topics/stoked-keyword-656/testtopics"; +const char kSubscriptionName[] = "stoked-keyword-656/testsubscription"; +const char kMessageData[] = "Message Data"; + +} // namespace + +grpc::string GetServiceAccountJsonKey() { + static grpc::string json_key; + if (json_key.empty()) { + std::ifstream json_key_file(FLAGS_service_account_key_file); + std::stringstream key_stream; + key_stream << json_key_file.rdbuf(); + json_key = key_stream.str(); + } + return json_key; +} + +int main(int argc, char** argv) { + grpc_init(); + google::ParseCommandLineFlags(&argc, &argv, true); + gpr_log(GPR_INFO, "Start TIPS client"); + + const int host_port_buf_size = 1024; + char host_port[host_port_buf_size]; + snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), + FLAGS_server_port); + + std::unique_ptr creds; + if (FLAGS_service_account_key_file != "") { + grpc::string json_key = GetServiceAccountJsonKey(); + creds = grpc::CredentialsFactory::ServiceAccountCredentials( + json_key, FLAGS_oauth_scope, std::chrono::hours(1)); + } else { + creds = grpc::CredentialsFactory::ComputeEngineCredentials(); + } + + std::shared_ptr channel( + grpc::CreateTestChannel( + host_port, + FLAGS_server_host, + true, // enable SSL + true, // use prod roots + creds)); + + grpc::examples::tips::Publisher publisher(channel); + grpc::examples::tips::Subscriber subscriber(channel); + + grpc::string topic = kTopic; + + if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic); + + grpc::Status s = publisher.CreateTopic(topic); + gpr_log(GPR_INFO, "Create topic returns code %d, %s", + s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); + + s = publisher.GetTopic(topic); + gpr_log(GPR_INFO, "Get topic returns code %d, %s", + s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); + + s = publisher.Publish(topic, kMessageData); + gpr_log(GPR_INFO, "Publish returns code %d, %s", + s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); + + s = subscriber.CreateSubscription(kTopic, kSubscriptionName); + gpr_log(GPR_INFO, "create subscrption returns code %d, %s", + s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); + + s = publisher.DeleteTopic(kTopic); + gpr_log(GPR_INFO, "Delete topic returns code %d, %s", + s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); + + subscriber.Shutdown(); + publisher.Shutdown(); + channel.reset(); + grpc_shutdown(); + return 0; +} -- cgit v1.2.3 From b532ef897340701897975b673d35ef24b5da4825 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Mon, 2 Feb 2015 10:45:17 -0800 Subject: Impelment full logic of publish and subcribe. --- examples/tips/empty.proto | 2 ++ examples/tips/label.proto | 2 ++ examples/tips/main.cc | 49 ++++++++++++++++++++++++++++------------ examples/tips/publisher.cc | 9 ++++---- examples/tips/publisher.h | 10 ++++---- examples/tips/pubsub.proto | 2 ++ examples/tips/subscriber.cc | 19 +++++++++++----- examples/tips/subscriber.h | 12 ++++++---- examples/tips/subscriber_test.cc | 10 ++++++++ 9 files changed, 80 insertions(+), 35 deletions(-) (limited to 'examples/tips/main.cc') diff --git a/examples/tips/empty.proto b/examples/tips/empty.proto index adf66b5e61..86aaa846a2 100644 --- a/examples/tips/empty.proto +++ b/examples/tips/empty.proto @@ -1,3 +1,5 @@ +// This file will be moved to a new location. + syntax = "proto2"; package proto2; diff --git a/examples/tips/label.proto b/examples/tips/label.proto index e93ac9dea3..6ac786f078 100644 --- a/examples/tips/label.proto +++ b/examples/tips/label.proto @@ -1,3 +1,5 @@ +// This file will be moved to a new location. + // Labels provide a way to associate user-defined metadata with various // objects. Labels may be used to organize objects into non-hierarchical // groups; think metadata tags attached to mp3s. diff --git a/examples/tips/main.cc b/examples/tips/main.cc index 94a0bc7995..edccd69c28 100644 --- a/examples/tips/main.cc +++ b/examples/tips/main.cc @@ -53,6 +53,7 @@ DEFINE_int32(server_port, 443, "Server port."); DEFINE_string(server_host, "pubsub-staging.googleapis.com", "Server host to connect to"); +DEFINE_string(project_id, "", "GCE project id such as stoked-keyword-656"); DEFINE_string(service_account_key_file, "", "Path to service account json key file."); DEFINE_string(oauth_scope, @@ -61,9 +62,9 @@ DEFINE_string(oauth_scope, namespace { -const char kTopic[] = "/topics/stoked-keyword-656/testtopics"; -const char kSubscriptionName[] = "stoked-keyword-656/testsubscription"; -const char kMessageData[] = "Message Data"; +const char kTopic[] = "testtopics"; +const char kSubscriptionName[] = "testsubscription"; +const char kMessageData[] = "Test Data"; } // namespace @@ -83,10 +84,7 @@ int main(int argc, char** argv) { google::ParseCommandLineFlags(&argc, &argv, true); gpr_log(GPR_INFO, "Start TIPS client"); - const int host_port_buf_size = 1024; - char host_port[host_port_buf_size]; - snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), - FLAGS_server_port); + std::ostringstream ss; std::unique_ptr creds; if (FLAGS_service_account_key_file != "") { @@ -97,9 +95,10 @@ int main(int argc, char** argv) { creds = grpc::CredentialsFactory::ComputeEngineCredentials(); } + ss << FLAGS_server_host << ":" << FLAGS_server_port; std::shared_ptr channel( grpc::CreateTestChannel( - host_port, + ss.str(), FLAGS_server_host, true, // enable SSL true, // use prod roots @@ -108,8 +107,21 @@ int main(int argc, char** argv) { grpc::examples::tips::Publisher publisher(channel); grpc::examples::tips::Subscriber subscriber(channel); - grpc::string topic = kTopic; + GPR_ASSERT(FLAGS_project_id != ""); + ss.str(""); + ss << "/topics/" << FLAGS_project_id << "/" << kTopic; + grpc::string topic = ss.str(); + ss.str(""); + ss << FLAGS_project_id << "/" << kSubscriptionName; + grpc::string subscription_name = ss.str(); + + // Clean up test topic and subcription. + grpc::string subscription_topic; + if (subscriber.GetSubscription( + subscription_name, &subscription_topic).IsOk()) { + subscriber.DeleteSubscription(subscription_name); + } if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic); grpc::Status s = publisher.CreateTopic(topic); @@ -122,17 +134,26 @@ int main(int argc, char** argv) { s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); - s = publisher.Publish(topic, kMessageData); - gpr_log(GPR_INFO, "Publish returns code %d, %s", + s = subscriber.CreateSubscription(topic, subscription_name); + gpr_log(GPR_INFO, "create subscrption returns code %d, %s", s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); - s = subscriber.CreateSubscription(kTopic, kSubscriptionName); - gpr_log(GPR_INFO, "create subscrption returns code %d, %s", + s = publisher.Publish(topic, kMessageData); + gpr_log(GPR_INFO, "Publish %s returns code %d, %s", + kMessageData, s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); + + grpc::string data; + s = subscriber.Pull(subscription_name, &data); + gpr_log(GPR_INFO, "Pull %s", data.c_str()); + + s = subscriber.DeleteSubscription(subscription_name); + gpr_log(GPR_INFO, "Delete subscription returns code %d, %s", s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); - s = publisher.DeleteTopic(kTopic); + s = publisher.DeleteTopic(topic); gpr_log(GPR_INFO, "Delete topic returns code %d, %s", s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); diff --git a/examples/tips/publisher.cc b/examples/tips/publisher.cc index 238ea596a2..027c157da0 100644 --- a/examples/tips/publisher.cc +++ b/examples/tips/publisher.cc @@ -56,7 +56,7 @@ void Publisher::Shutdown() { stub_.reset(); } -Status Publisher::CreateTopic(grpc::string topic) { +Status Publisher::CreateTopic(const string& topic) { Topic request; Topic response; request.set_name(topic); @@ -73,7 +73,7 @@ Status Publisher::ListTopics() { return stub_->ListTopics(&context, request, &response); } -Status Publisher::GetTopic(grpc::string topic) { +Status Publisher::GetTopic(const string& topic) { GetTopicRequest request; Topic response; ClientContext context; @@ -83,7 +83,7 @@ Status Publisher::GetTopic(grpc::string topic) { return stub_->GetTopic(&context, request, &response); } -Status Publisher::DeleteTopic(grpc::string topic) { +Status Publisher::DeleteTopic(const string& topic) { DeleteTopicRequest request; proto2::Empty response; ClientContext context; @@ -93,8 +93,7 @@ Status Publisher::DeleteTopic(grpc::string topic) { return stub_->DeleteTopic(&context, request, &response); } -Status Publisher::Publish(const grpc::string& topic, - const grpc::string& data) { +Status Publisher::Publish(const string& topic, const string& data) { PublishRequest request; proto2::Empty response; ClientContext context; diff --git a/examples/tips/publisher.h b/examples/tips/publisher.h index a97dbe6de2..b1be4d9dcb 100644 --- a/examples/tips/publisher.h +++ b/examples/tips/publisher.h @@ -45,15 +45,15 @@ namespace tips { class Publisher { public: - Publisher(std::shared_ptr channel); + Publisher(std::shared_ptr channel); void Shutdown(); - Status CreateTopic(grpc::string topic); - Status GetTopic(grpc::string topic); - Status DeleteTopic(grpc::string topic); + Status CreateTopic(const string& topic); + Status GetTopic(const string& topic); + Status DeleteTopic(const string& topic); Status ListTopics(); - Status Publish(const grpc::string& topic, const grpc::string& data); + Status Publish(const string& topic, const string& data); private: std::unique_ptr stub_; diff --git a/examples/tips/pubsub.proto b/examples/tips/pubsub.proto index 0b3bd5d012..15ada6063a 100644 --- a/examples/tips/pubsub.proto +++ b/examples/tips/pubsub.proto @@ -1,3 +1,5 @@ +// This file will be moved to new location. + // Specification of the Pubsub API. syntax = "proto2"; diff --git a/examples/tips/subscriber.cc b/examples/tips/subscriber.cc index 2e2370ee2d..6dae3ce3a9 100644 --- a/examples/tips/subscriber.cc +++ b/examples/tips/subscriber.cc @@ -56,8 +56,7 @@ void Subscriber::Shutdown() { stub_.reset(); } -Status Subscriber::CreateSubscription(const grpc::string& topic, - const grpc::string& name) { +Status Subscriber::CreateSubscription(const string& topic, const string& name) { tech::pubsub::Subscription request; tech::pubsub::Subscription response; ClientContext context; @@ -68,8 +67,7 @@ Status Subscriber::CreateSubscription(const grpc::string& topic, return stub_->CreateSubscription(&context, request, &response); } -Status Subscriber::GetSubscription(const grpc::string& name, - grpc::string* topic) { +Status Subscriber::GetSubscription(const string& name, string* topic) { tech::pubsub::GetSubscriptionRequest request; tech::pubsub::Subscription response; ClientContext context; @@ -81,8 +79,17 @@ Status Subscriber::GetSubscription(const grpc::string& name, return s; } -Status Subscriber::Pull(const grpc::string& name, - grpc::string* data) { +Status Subscriber::DeleteSubscription(const string& name) { + tech::pubsub::DeleteSubscriptionRequest request; + proto2::Empty response; + ClientContext context; + + request.set_subscription(name); + + return stub_->DeleteSubscription(&context, request, &response); +} + +Status Subscriber::Pull(const string& name, string* data) { tech::pubsub::PullRequest request; tech::pubsub::PullResponse response; ClientContext context; diff --git a/examples/tips/subscriber.h b/examples/tips/subscriber.h index 38345c0c5a..d9911149bb 100644 --- a/examples/tips/subscriber.h +++ b/examples/tips/subscriber.h @@ -45,15 +45,17 @@ namespace tips { class Subscriber { public: - Subscriber(std::shared_ptr channel); + Subscriber(std::shared_ptr channel); void Shutdown(); - Status CreateSubscription(const grpc::string& topic, - const grpc::string& name); + Status CreateSubscription(const string& topic, + const string& name); - Status GetSubscription(const grpc::string& name, grpc::string* topic); + Status GetSubscription(const string& name, string* topic); - Status Pull(const grpc::string& name, grpc::string* data); + Status DeleteSubscription(const string& name); + + Status Pull(const string& name, string* data); private: std::unique_ptr stub_; diff --git a/examples/tips/subscriber_test.cc b/examples/tips/subscriber_test.cc index 4ff93643ae..9c46718308 100644 --- a/examples/tips/subscriber_test.cc +++ b/examples/tips/subscriber_test.cc @@ -73,6 +73,14 @@ class SubscriberServiceImpl : public tech::pubsub::SubscriberService::Service { return Status::OK; } + Status DeleteSubscription( + ServerContext* context, + const tech::pubsub::DeleteSubscriptionRequest* request, + proto2::Empty* response) override { + EXPECT_EQ(request->subscription(), kSubscriptionName); + return Status::OK; + } + Status Pull(ServerContext* context, const tech::pubsub::PullRequest* request, tech::pubsub::PullResponse* response) override { @@ -133,6 +141,8 @@ TEST_F(SubscriberTest, TestSubscriber) { grpc::string data; EXPECT_TRUE(subscriber_->Pull(kSubscriptionName, &data).IsOk()); + + EXPECT_TRUE(subscriber_->DeleteSubscription(kSubscriptionName).IsOk()); } } // namespace -- cgit v1.2.3 From 405392c2e8b7b9dcde7c47fae1607a3a26635e6f Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 3 Feb 2015 10:28:39 -0800 Subject: fixed typos and add ListTopics implementation. --- examples/tips/main.cc | 16 ++++++++++++++-- examples/tips/publisher.cc | 27 +++++++++++++++++++++------ examples/tips/publisher.h | 11 ++++++----- examples/tips/publisher_test.cc | 15 +++++++++++++-- examples/tips/pubsub.proto | 2 +- examples/tips/subscriber.cc | 10 ++++++---- examples/tips/subscriber.h | 10 +++++----- examples/tips/subscriber_test.cc | 3 --- 8 files changed, 66 insertions(+), 28 deletions(-) (limited to 'examples/tips/main.cc') diff --git a/examples/tips/main.cc b/examples/tips/main.cc index edccd69c28..df9d984ae1 100644 --- a/examples/tips/main.cc +++ b/examples/tips/main.cc @@ -69,7 +69,7 @@ const char kMessageData[] = "Test Data"; } // namespace grpc::string GetServiceAccountJsonKey() { - static grpc::string json_key; + grpc::string json_key; if (json_key.empty()) { std::ifstream json_key_file(FLAGS_service_account_key_file); std::stringstream key_stream; @@ -116,7 +116,7 @@ int main(int argc, char** argv) { ss << FLAGS_project_id << "/" << kSubscriptionName; grpc::string subscription_name = ss.str(); - // Clean up test topic and subcription. + // Clean up test topic and subcription if they exist before. grpc::string subscription_topic; if (subscriber.GetSubscription( subscription_name, &subscription_topic).IsOk()) { @@ -134,6 +134,18 @@ int main(int argc, char** argv) { s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); + std::vector topics; + s = publisher.ListTopics(FLAGS_project_id, &topics); + gpr_log(GPR_INFO, "List topic returns code %d, %s", + s.code(), s.details().c_str()); + bool topic_found = false; + for (unsigned int i = 0; i < topics.size(); i++) { + if (topics[i] == topic) topic_found = true; + gpr_log(GPR_INFO, "topic: %s", topics[i].c_str()); + } + GPR_ASSERT(s.IsOk()); + GPR_ASSERT(topic_found); + s = subscriber.CreateSubscription(topic, subscription_name); gpr_log(GPR_INFO, "create subscrption returns code %d, %s", s.code(), s.details().c_str()); diff --git a/examples/tips/publisher.cc b/examples/tips/publisher.cc index 027c157da0..085e6c5b6f 100644 --- a/examples/tips/publisher.cc +++ b/examples/tips/publisher.cc @@ -31,6 +31,8 @@ * */ +#include + #include #include "examples/tips/publisher.h" @@ -56,7 +58,7 @@ void Publisher::Shutdown() { stub_.reset(); } -Status Publisher::CreateTopic(const string& topic) { +Status Publisher::CreateTopic(const grpc::string& topic) { Topic request; Topic response; request.set_name(topic); @@ -65,15 +67,28 @@ Status Publisher::CreateTopic(const string& topic) { return stub_->CreateTopic(&context, request, &response); } -Status Publisher::ListTopics() { +Status Publisher::ListTopics(const grpc::string& project_id, + std::vector* topics) { ListTopicsRequest request; ListTopicsResponse response; ClientContext context; - return stub_->ListTopics(&context, request, &response); + std::stringstream ss; + ss << "cloud.googleapis.com/project in (/projects/" << project_id << ")"; + request.set_query(ss.str()); + + Status s = stub_->ListTopics(&context, request, &response); + + tech::pubsub::Topic topic; + for (int i = 0; i < response.topic_size(); i++) { + topic = response.topic(i); + topics->push_back(topic.name()); + } + + return s; } -Status Publisher::GetTopic(const string& topic) { +Status Publisher::GetTopic(const grpc::string& topic) { GetTopicRequest request; Topic response; ClientContext context; @@ -83,7 +98,7 @@ Status Publisher::GetTopic(const string& topic) { return stub_->GetTopic(&context, request, &response); } -Status Publisher::DeleteTopic(const string& topic) { +Status Publisher::DeleteTopic(const grpc::string& topic) { DeleteTopicRequest request; proto2::Empty response; ClientContext context; @@ -93,7 +108,7 @@ Status Publisher::DeleteTopic(const string& topic) { return stub_->DeleteTopic(&context, request, &response); } -Status Publisher::Publish(const string& topic, const string& data) { +Status Publisher::Publish(const grpc::string& topic, const grpc::string& data) { PublishRequest request; proto2::Empty response; ClientContext context; diff --git a/examples/tips/publisher.h b/examples/tips/publisher.h index b1be4d9dcb..d8d7353826 100644 --- a/examples/tips/publisher.h +++ b/examples/tips/publisher.h @@ -48,12 +48,13 @@ class Publisher { Publisher(std::shared_ptr channel); void Shutdown(); - Status CreateTopic(const string& topic); - Status GetTopic(const string& topic); - Status DeleteTopic(const string& topic); - Status ListTopics(); + Status CreateTopic(const grpc::string& topic); + Status GetTopic(const grpc::string& topic); + Status DeleteTopic(const grpc::string& topic); + Status ListTopics(const grpc::string& project_id, + std::vector* topics); - Status Publish(const string& topic, const string& data); + Status Publish(const grpc::string& topic, const grpc::string& data); private: std::unique_ptr stub_; diff --git a/examples/tips/publisher_test.cc b/examples/tips/publisher_test.cc index 7f845fed23..cb949e96fa 100644 --- a/examples/tips/publisher_test.cc +++ b/examples/tips/publisher_test.cc @@ -51,6 +51,7 @@ namespace grpc { namespace testing { namespace { +const char kProjectId[] = "project id"; const char kTopic[] = "test topic"; const char kMessageData[] = "test message data"; @@ -80,7 +81,11 @@ class PublisherServiceImpl : public tech::pubsub::PublisherService::Service { Status ListTopics(ServerContext* context, const ::tech::pubsub::ListTopicsRequest* request, ::tech::pubsub::ListTopicsResponse* response) override { - return Status::OK; + std::stringstream ss; + ss << "cloud.googleapis.com/project in (/projects/" << kProjectId << ")"; + EXPECT_EQ(request->query(), ss.str()); + response->add_topic()->set_name(kTopic); + return Status::OK; } Status DeleteTopic(ServerContext* context, @@ -124,9 +129,15 @@ class PublisherTest : public ::testing::Test { TEST_F(PublisherTest, TestPublisher) { EXPECT_TRUE(publisher_->CreateTopic(kTopic).IsOk()); + EXPECT_TRUE(publisher_->Publish(kTopic, kMessageData).IsOk()); + EXPECT_TRUE(publisher_->GetTopic(kTopic).IsOk()); - EXPECT_TRUE(publisher_->ListTopics().IsOk()); + + std::vector topics; + EXPECT_TRUE(publisher_->ListTopics(kProjectId, &topics).IsOk()); + EXPECT_EQ(topics.size(), 1); + EXPECT_EQ(topics[0], kTopic); } } // namespace diff --git a/examples/tips/pubsub.proto b/examples/tips/pubsub.proto index 15ada6063a..a2dd2f5ca8 100644 --- a/examples/tips/pubsub.proto +++ b/examples/tips/pubsub.proto @@ -1,4 +1,4 @@ -// This file will be moved to new location. +// This file will be moved to a new location. // Specification of the Pubsub API. diff --git a/examples/tips/subscriber.cc b/examples/tips/subscriber.cc index 6dae3ce3a9..c0673223ae 100644 --- a/examples/tips/subscriber.cc +++ b/examples/tips/subscriber.cc @@ -56,7 +56,8 @@ void Subscriber::Shutdown() { stub_.reset(); } -Status Subscriber::CreateSubscription(const string& topic, const string& name) { +Status Subscriber::CreateSubscription(const grpc::string& topic, + const grpc::string& name) { tech::pubsub::Subscription request; tech::pubsub::Subscription response; ClientContext context; @@ -67,7 +68,8 @@ Status Subscriber::CreateSubscription(const string& topic, const string& name) { return stub_->CreateSubscription(&context, request, &response); } -Status Subscriber::GetSubscription(const string& name, string* topic) { +Status Subscriber::GetSubscription(const grpc::string& name, + grpc::string* topic) { tech::pubsub::GetSubscriptionRequest request; tech::pubsub::Subscription response; ClientContext context; @@ -79,7 +81,7 @@ Status Subscriber::GetSubscription(const string& name, string* topic) { return s; } -Status Subscriber::DeleteSubscription(const string& name) { +Status Subscriber::DeleteSubscription(const grpc::string& name) { tech::pubsub::DeleteSubscriptionRequest request; proto2::Empty response; ClientContext context; @@ -89,7 +91,7 @@ Status Subscriber::DeleteSubscription(const string& name) { return stub_->DeleteSubscription(&context, request, &response); } -Status Subscriber::Pull(const string& name, string* data) { +Status Subscriber::Pull(const grpc::string& name, grpc::string* data) { tech::pubsub::PullRequest request; tech::pubsub::PullResponse response; ClientContext context; diff --git a/examples/tips/subscriber.h b/examples/tips/subscriber.h index d9911149bb..ed706ff170 100644 --- a/examples/tips/subscriber.h +++ b/examples/tips/subscriber.h @@ -48,14 +48,14 @@ class Subscriber { Subscriber(std::shared_ptr channel); void Shutdown(); - Status CreateSubscription(const string& topic, - const string& name); + Status CreateSubscription(const grpc::string& topic, + const grpc::string& name); - Status GetSubscription(const string& name, string* topic); + Status GetSubscription(const grpc::string& name, grpc::string* topic); - Status DeleteSubscription(const string& name); + Status DeleteSubscription(const grpc::string& name); - Status Pull(const string& name, string* data); + Status Pull(const grpc::string& name, grpc::string* data); private: std::unique_ptr stub_; diff --git a/examples/tips/subscriber_test.cc b/examples/tips/subscriber_test.cc index 9c46718308..595a6a13a1 100644 --- a/examples/tips/subscriber_test.cc +++ b/examples/tips/subscriber_test.cc @@ -45,8 +45,6 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" -using grpc::ChannelInterface; - namespace grpc { namespace testing { namespace { @@ -132,7 +130,6 @@ TEST_F(SubscriberTest, TestSubscriber) { EXPECT_TRUE(subscriber_->CreateSubscription(kTopic, kSubscriptionName).IsOk()); - grpc::string topic; EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName, &topic).IsOk()); -- cgit v1.2.3