|
|
@ -51,14 +51,14 @@ |
|
|
|
#include "examples/pubsub/subscriber.h" |
|
|
|
#include "examples/pubsub/subscriber.h" |
|
|
|
|
|
|
|
|
|
|
|
DEFINE_int32(server_port, 443, "Server port."); |
|
|
|
DEFINE_int32(server_port, 443, "Server port."); |
|
|
|
DEFINE_string(server_host, |
|
|
|
DEFINE_string(server_host, "pubsub-staging.googleapis.com", |
|
|
|
"pubsub-staging.googleapis.com", "Server host to connect to"); |
|
|
|
"Server host to connect to"); |
|
|
|
DEFINE_string(project_id, "", "GCE project id such as stoked-keyword-656"); |
|
|
|
DEFINE_string(project_id, "", "GCE project id such as stoked-keyword-656"); |
|
|
|
|
|
|
|
|
|
|
|
// In some distros, gflags is in the namespace google, and in some others,
|
|
|
|
// In some distros, gflags is in the namespace google, and in some others,
|
|
|
|
// in gflags. This hack is enabling us to find both.
|
|
|
|
// in gflags. This hack is enabling us to find both.
|
|
|
|
namespace google { } |
|
|
|
namespace google {} |
|
|
|
namespace gflags { } |
|
|
|
namespace gflags {} |
|
|
|
using namespace google; |
|
|
|
using namespace google; |
|
|
|
using namespace gflags; |
|
|
|
using namespace gflags; |
|
|
|
|
|
|
|
|
|
|
@ -92,32 +92,32 @@ int main(int argc, char** argv) { |
|
|
|
grpc::string topic = ss.str(); |
|
|
|
grpc::string topic = ss.str(); |
|
|
|
|
|
|
|
|
|
|
|
ss.str(""); |
|
|
|
ss.str(""); |
|
|
|
ss << FLAGS_project_id << "/" << kSubscriptionName; |
|
|
|
ss << FLAGS_project_id << "/" << kSubscriptionName; |
|
|
|
grpc::string subscription_name = ss.str(); |
|
|
|
grpc::string subscription_name = ss.str(); |
|
|
|
|
|
|
|
|
|
|
|
// Clean up test topic and subcription if they exist before.
|
|
|
|
// Clean up test topic and subcription if they exist before.
|
|
|
|
grpc::string subscription_topic; |
|
|
|
grpc::string subscription_topic; |
|
|
|
if (subscriber.GetSubscription( |
|
|
|
if (subscriber.GetSubscription(subscription_name, &subscription_topic) |
|
|
|
subscription_name, &subscription_topic).IsOk()) { |
|
|
|
.IsOk()) { |
|
|
|
subscriber.DeleteSubscription(subscription_name); |
|
|
|
subscriber.DeleteSubscription(subscription_name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic); |
|
|
|
if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic); |
|
|
|
|
|
|
|
|
|
|
|
grpc::Status s = publisher.CreateTopic(topic); |
|
|
|
grpc::Status s = publisher.CreateTopic(topic); |
|
|
|
gpr_log(GPR_INFO, "Create topic returns code %d, %s", |
|
|
|
gpr_log(GPR_INFO, "Create topic returns code %d, %s", s.code(), |
|
|
|
s.code(), s.details().c_str()); |
|
|
|
s.details().c_str()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
|
|
|
|
|
|
|
|
s = publisher.GetTopic(topic); |
|
|
|
s = publisher.GetTopic(topic); |
|
|
|
gpr_log(GPR_INFO, "Get topic returns code %d, %s", |
|
|
|
gpr_log(GPR_INFO, "Get topic returns code %d, %s", s.code(), |
|
|
|
s.code(), s.details().c_str()); |
|
|
|
s.details().c_str()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<grpc::string> topics; |
|
|
|
std::vector<grpc::string> topics; |
|
|
|
s = publisher.ListTopics(FLAGS_project_id, &topics); |
|
|
|
s = publisher.ListTopics(FLAGS_project_id, &topics); |
|
|
|
gpr_log(GPR_INFO, "List topic returns code %d, %s", |
|
|
|
gpr_log(GPR_INFO, "List topic returns code %d, %s", s.code(), |
|
|
|
s.code(), s.details().c_str()); |
|
|
|
s.details().c_str()); |
|
|
|
bool topic_found = false; |
|
|
|
bool topic_found = false; |
|
|
|
for (unsigned int i = 0; i < topics.size(); i++) { |
|
|
|
for (unsigned int i = 0; i < topics.size(); i++) { |
|
|
|
if (topics[i] == topic) topic_found = true; |
|
|
|
if (topics[i] == topic) topic_found = true; |
|
|
@ -127,27 +127,27 @@ int main(int argc, char** argv) { |
|
|
|
GPR_ASSERT(topic_found); |
|
|
|
GPR_ASSERT(topic_found); |
|
|
|
|
|
|
|
|
|
|
|
s = subscriber.CreateSubscription(topic, subscription_name); |
|
|
|
s = subscriber.CreateSubscription(topic, subscription_name); |
|
|
|
gpr_log(GPR_INFO, "create subscrption returns code %d, %s", |
|
|
|
gpr_log(GPR_INFO, "create subscrption returns code %d, %s", s.code(), |
|
|
|
s.code(), s.details().c_str()); |
|
|
|
s.details().c_str()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
|
|
|
|
|
|
|
|
s = publisher.Publish(topic, kMessageData); |
|
|
|
s = publisher.Publish(topic, kMessageData); |
|
|
|
gpr_log(GPR_INFO, "Publish %s returns code %d, %s", |
|
|
|
gpr_log(GPR_INFO, "Publish %s returns code %d, %s", kMessageData, s.code(), |
|
|
|
kMessageData, s.code(), s.details().c_str()); |
|
|
|
s.details().c_str()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
|
|
|
|
|
|
|
|
grpc::string data; |
|
|
|
grpc::string data; |
|
|
|
s = subscriber.Pull(subscription_name, &data); |
|
|
|
s = subscriber.Pull(subscription_name, &data); |
|
|
|
gpr_log(GPR_INFO, "Pull %s", data.c_str()); |
|
|
|
gpr_log(GPR_INFO, "Pull %s", data.c_str()); |
|
|
|
|
|
|
|
|
|
|
|
s = subscriber.DeleteSubscription(subscription_name); |
|
|
|
s = subscriber.DeleteSubscription(subscription_name); |
|
|
|
gpr_log(GPR_INFO, "Delete subscription returns code %d, %s", |
|
|
|
gpr_log(GPR_INFO, "Delete subscription returns code %d, %s", s.code(), |
|
|
|
s.code(), s.details().c_str()); |
|
|
|
s.details().c_str()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
|
|
|
|
|
|
|
|
s = publisher.DeleteTopic(topic); |
|
|
|
s = publisher.DeleteTopic(topic); |
|
|
|
gpr_log(GPR_INFO, "Delete topic returns code %d, %s", |
|
|
|
gpr_log(GPR_INFO, "Delete topic returns code %d, %s", s.code(), |
|
|
|
s.code(), s.details().c_str()); |
|
|
|
s.details().c_str()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
GPR_ASSERT(s.IsOk()); |
|
|
|
|
|
|
|
|
|
|
|
subscriber.Shutdown(); |
|
|
|
subscriber.Shutdown(); |
|
|
|