1919// [START pubsub_quickstart]
2020// Imports the Google Cloud client library
2121
22- import com .google .api .gax .core .RpcFuture ;
23- import com .google .cloud .pubsub .spi .v1 .Publisher ;
2422import com .google .cloud .pubsub .spi .v1 .PublisherClient ;
25- import com .google .protobuf .ByteString ;
26- import com .google .pubsub .v1 .PubsubMessage ;
2723import com .google .pubsub .v1 .TopicName ;
2824
2925public class QuickstartSample {
@@ -36,26 +32,8 @@ public static void main(String... args) throws Exception {
3632 try (PublisherClient publisherClient = PublisherClient .create ()) {
3733 publisherClient .createTopic (topic );
3834 }
39- System .out .printf ("Topic %s:%s created.\n " , topic .getProject (), topic .getTopic ());
4035
41- // Creates a publisher
42- Publisher publisher = null ;
43- try {
44- publisher = Publisher .newBuilder (topic ).build ();
45-
46- //Publish a message asynchronously
47- String message = "my-message" ;
48- ByteString data = ByteString .copyFromUtf8 (message );
49- PubsubMessage pubsubMessage = PubsubMessage .newBuilder ().setData (data ).build ();
50- RpcFuture <String > messageIdFuture = publisher .publish (pubsubMessage );
51-
52- //Print message id of published message
53- System .out .println ("published with message ID: " + messageIdFuture .get ());
54- } finally {
55- if (publisher != null ) {
56- publisher .shutdown ();
57- }
58- }
36+ System .out .printf ("Topic %s:%s created.\n " , topic .getProject (), topic .getTopic ());
5937 }
6038}
6139// [END pubsub_quickstart]
0 commit comments