C++ pubsub subscribers not pulling messages #10386
-
Hi all, I'm attempting to test my pubsub code but am running into issues with creating subscriber objects connecting to subscriptions. I have a pubsub emulator running in a docker container separate from the container running the pubsub code. I'm able to create subscriptions to the topics running in the emulator container from my pubsub container but am not receiving published messages. I have a unique subscription created for each topic (randomly generated string of numbers) so I know that my code is creating unique subscription Id's. Below are the relevant parts of the code: Class members:
Functions called:
Function definitions:
In this last function I commented out the code I implemented and reverted back to the example code to try and isolate the problem there but I still am not receiving any messages. I'm also able to confirm that I'm am actually publishing messages to the topics correctly as well. I suspect that my issue is not using the correct subscription object when calling google:: cloud ::pubsub::MakeSubscriberConnection(subscription) but am not sure. It seems like I should be passing the object returned from subscription_admin_client.CreateSubscription() instead of passing a regular subscription object that only contains the project and subscription ids? Lastly I attempted to output info about the session object from subscriber.Subscribe via:
but had to comment out everything but the top 2 as the process was hung trying to get the other information. Not sure if that info was valuable or not. valid() returned 1 but is_ready() returned 0. Thanks for the help so far. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is a little too much code for me to diagnose. Can you create a smaller, reproducible program that shows the problem? I will try to answer your specific questions if I can:
No. You should be able to use a Most applications create a subscription (via
You are creating and then deleting the If you use std::vector<google::cloud::future<Status>>
createLocalSubscribers(
google::cloud::pubsub::Subscriber subscriber,
std::vector<google::cloud::pubsub::Subscription> subscriptionsList) {
WIRELOG_DEBUG("Creating local subscribers")
std::vector<google::cloud::future<Status>> sessions;
try {
for (auto const& subscription : subscriptionsList) {
auto session = subscriber.Subscribe(
[](google::cloud::pubsub::Message const &m, google::cloud::pubsub::AckHandler h) {
std::move(h).ack();
WIRELOG_DEBUG("Got message")
WIRELOG_DEBUG( "Received message " << m.data())
},
// *** NEW ** override the default subscription and reuse the Subscriber.
google::cloud::Options{}.set<google::cloud::pubsub::SubscriptionOption>(subscription));
sessions.push_back(std::move(session);
}
} catch (std::exception &e) {
WIRELOG_DEBUG("Exception caught when creating subscribers: " << e.what())
throw;
}
return sessions;
}
As an aside, as I don't think it is relevant to the problem at hand. You seem to be using https://en.cppreference.com/w/cpp/numeric/random/rand
This is a large topic, but this is a good start: |
Beta Was this translation helpful? Give feedback.
This is a little too much code for me to diagnose. Can you create a smaller, reproducible program that shows the problem? I will try to answer your specific questions if I can:
No. You should be able to use a
pubsub::Subscription
there. Apubusb::Subscription
is a convenience class to just hold the name (just a string real…