19
19
// [START pubsub_quickstart]
20
20
// Imports the Google Cloud client library
21
21
22
- import com .google .api .gax .core .RpcFuture ;
23
- import com .google .cloud .pubsub .spi .v1 .Publisher ;
24
22
import com .google .cloud .pubsub .spi .v1 .PublisherClient ;
25
- import com .google .protobuf .ByteString ;
26
- import com .google .pubsub .v1 .PubsubMessage ;
27
23
import com .google .pubsub .v1 .TopicName ;
28
24
29
25
public class QuickstartSample {
@@ -36,26 +32,8 @@ public static void main(String... args) throws Exception {
36
32
try (PublisherClient publisherClient = PublisherClient .create ()) {
37
33
publisherClient .createTopic (topic );
38
34
}
39
- System .out .printf ("Topic %s:%s created.\n " , topic .getProject (), topic .getTopic ());
40
35
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 ());
59
37
}
60
38
}
61
39
// [END pubsub_quickstart]
0 commit comments