public ListTopicSubscriptionsPagedResponse listTopicSubscriptions ( String topicId ) throws Exception { // [START pubsub_list_topic_subscriptions] try ( TopicAdminClient topicAdminClient = TopicAdminClient . create ( ) ) { ProjectTopicName topicName = ProjectTopicName . of ( projectId , topicId ) ; ListTopicSubscriptionsRequest request = ListTopicSubscriptionsRequest . newBuilder ( ) . setTopic ( topicName . toString ( ) ) . build ( ) ; ListTopicSubscriptionsPagedResponse response = topicAdminClient . listTopicSubscriptions ( request ) ; Iterable < String > subscriptionNames = response . iterateAll ( ) ; for ( String subscriptionName : subscriptionNames ) { // do something with the subscription name } return response ; } // [END pubsub_list_topic_subscriptions] }
Example of listing subscriptions for a topic .