public static void createTopic ( Pubsub client , String fullTopicName ) throws IOException { System . out . println ( "fullTopicName " + fullTopicName ) ; try { client . projects ( ) . topics ( ) . get ( fullTopicName ) . execute ( ) ; } catch ( GoogleJsonResponseException e ) { if ( e . getStatusCode ( ) == HttpStatusCodes . STATUS_CODE_NOT_FOUND ) { Topic topic = client . projects ( ) . topics ( ) . create ( fullTopicName , new Topic ( ) ) . execute ( ) ; System . out . printf ( "Topic %s was created.%n" , topic . getName ( ) ) ; } } }
Create a topic if it doesn t exist .