Hello all,
Could you please suggest a way to get a number of "undelivered messages" in the Pub/Sub in the specific subscription_id via API without consuming messages?
Ideally using some Java library /client.
Check out the Monitoring Java client library.
The metric you are looking for is subscription/num_undelivered_messages.
Note that if you are trying to build an auto scaler, GKE and Compute Engine managed instance groups already have this functionality built in. So does Dataflow and, likely, anything you use with a push subscription (Functions, Cloud Run, App Engine).