Skip to content

Commit

Permalink
Merge pull request #530 from GoogleCloudPlatform/pubsub_quickstart
Browse files Browse the repository at this point in the history
removing publish from quickstart
  • Loading branch information
jabubake authored Feb 21, 2017
2 parents eae8a48 + 53ae569 commit 5e73738
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
// [START pubsub_quickstart]
// Imports the Google Cloud client library

import com.google.api.gax.core.RpcFuture;
import com.google.cloud.pubsub.spi.v1.Publisher;
import com.google.cloud.pubsub.spi.v1.PublisherClient;
import com.google.protobuf.ByteString;
import com.google.pubsub.v1.PubsubMessage;
import com.google.pubsub.v1.TopicName;

public class QuickstartSample {
Expand All @@ -36,26 +32,8 @@ public static void main(String... args) throws Exception {
try (PublisherClient publisherClient = PublisherClient.create()) {
publisherClient.createTopic(topic);
}
System.out.printf("Topic %s:%s created.\n", topic.getProject(), topic.getTopic());

// Creates a publisher
Publisher publisher = null;
try {
publisher = Publisher.newBuilder(topic).build();

//Publish a message asynchronously
String message = "my-message";
ByteString data = ByteString.copyFromUtf8(message);
PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
RpcFuture<String> messageIdFuture = publisher.publish(pubsubMessage);

//Print message id of published message
System.out.println("published with message ID: " + messageIdFuture.get());
} finally {
if (publisher != null) {
publisher.shutdown();
}
}
System.out.printf("Topic %s:%s created.\n", topic.getProject(), topic.getTopic());
}
}
// [END pubsub_quickstart]
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,5 @@ public void testQuickstart() throws Exception {
QuickstartSample.main(projectId);
String got = bout.toString();
assertThat(got).contains("my-new-topic created.");
assertThat(got).contains("published with message ID");
}
}

0 comments on commit 5e73738

Please sign in to comment.