public Topic getTopic ( String topicId ) throws Exception { // [START pubsub_get_topic] try ( TopicAdminClient topicAdminClient = TopicAdminClient . create ( ) ) { ProjectTopicName topicName = ProjectTopicName . of ( projectId , topicId ) ; Topic topic = topicAdminClient . getTopic ( topicName ) ; return topic ; } // [END pubsub_get_topic] }
Example of getting a topic .