When to create pubsub client subscription? #10320
-
Greetings everyone, I'm looking for clarification on pubsub subscriptions when using the C++ client library. After reading the documentation it seems that two different types of "subscriptions" exist. The first type are the subscriptions that exist on GCP and attach directly to topics. The second exist inside user code and are used to connect to the subscriptions that exist on GCP. I was hoping someone would double check my logic to make sure I'm using the client library correctly. In my project I need the capability to deploy N number of copies of a particular microservice that all run concurrently. I have a set number of topics which each separate microservice will need to subscribe to. The logic flow is as follows:
I run this code for each topic and subscription that should bind to it.
and then for each subscription object created above use it to create a subscriber:
Once all the setup is complete I should be able to start pulling messages and reading them from the messages queue I created. Thanks for the help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
In principle this will work. You did not mention the expected message rates over these topics, some optimization may be required if the message rate is sufficiently high (at a guess, anything over 1,000 messages/second). I expect that fine tuning the implicitly created background thread pools, connection pools, and other low-level details may require some work. Here are some starting ideas:
|
Beta Was this translation helpful? Give feedback.
In principle this will work. You did not mention the expected message rates over these topics, some optimization may be required if the message rate is sufficiently high (at a guess, anything over 1,000 messages/second).
I expect that fine tuning the implicitly created background thread pools, connection pools, and other low-level details may require some work. Here are some starting ideas:
Each
subscriber
in you loop creates a thread pool to service the request. You may need to create your own thread pool using GrpcCompletionQueueOption, or reduce the size of the pool on each subscriber GrpcBackgroundThreadPoolSizeOption.Each subscriber creates a pool of gRPC channels, the default c…