diff --git a/pubsub/cloud-client/README.md b/pubsub/cloud-client/README.md
index c621c2393c2..1f5232b4bbe 100644
--- a/pubsub/cloud-client/README.md
+++ b/pubsub/cloud-client/README.md
@@ -2,7 +2,7 @@
[Google Cloud Pub/Sub][pubsub] is a fully-managed real-time messaging service that allows you to
send and receive messages between independent applications.
-These sample Java applications demonstrate how to access the Pub/Sub API using
+This sample Java application demonstrates how to access the Pub/Sub API using
the [Google Cloud Client Library for Java][google-cloud-java].
[pubsub]: https://cloud.google.com/pubsub/
@@ -10,23 +10,25 @@ the [Google Cloud Client Library for Java][google-cloud-java].
## Quickstart
-Install [Maven](http://maven.apache.org/).
+#### Setup
+- Install [Maven](http://maven.apache.org/)
+- Install the [Google Cloud SDK](https://cloud.google.com/sdk/) and run :
-Build your project with:
- mvn clean package -DskipTests
+ gcloud config set project [YOUR PROJECT ID]
-## Testing
-To run the tests for this sample, first set the `GOOGLE_CLOUD_PROJECT`
-environment variable.
+- Build your project with:
- export GOOGLE_CLOUD_PROJECT=my-project
-Then run the tests with Maven.
+ mvn clean package -DskipTests
+
+#### Testing
+
+Run the tests with Maven.
mvn clean verify
-### Creating a new topic (using the quickstart sample)
+#### Creating a new topic (using the quickstart sample)
mvn exec:java -Dexec.mainClass=com.example.pubsub.QuickstartSample
diff --git a/pubsub/cloud-client/pom.xml b/pubsub/cloud-client/pom.xml
index 71f54b4d632..37cb102eda8 100644
--- a/pubsub/cloud-client/pom.xml
+++ b/pubsub/cloud-client/pom.xml
@@ -37,7 +37,7 @@
com.google.cloud
google-cloud-pubsub
- 0.9.2-alpha
+ 0.9.4-alpha
diff --git a/pubsub/cloud-client/src/main/java/com/example/pubsub/QuickstartSample.java b/pubsub/cloud-client/src/main/java/com/example/pubsub/QuickstartSample.java
index fb4bd1fc72f..ac5dcefc2af 100644
--- a/pubsub/cloud-client/src/main/java/com/example/pubsub/QuickstartSample.java
+++ b/pubsub/cloud-client/src/main/java/com/example/pubsub/QuickstartSample.java
@@ -19,6 +19,7 @@
// [START pubsub_quickstart]
// Imports the Google Cloud client library
+import com.google.cloud.ServiceOptions;
import com.google.cloud.pubsub.spi.v1.PublisherClient;
import com.google.pubsub.v1.TopicName;
@@ -26,9 +27,14 @@ public class QuickstartSample {
public static void main(String... args) throws Exception {
+ // Your Google Cloud Platform project ID
+ String projectId = ServiceOptions.getDefaultProjectId();
+
+ // Your topic ID
+ String topicId = "my-new-topic";
+
// Create a new topic
- String projectId = args[0];
- TopicName topic = TopicName.create(projectId, "my-new-topic");
+ TopicName topic = TopicName.create(projectId, topicId);
try (PublisherClient publisherClient = PublisherClient.create()) {
publisherClient.createTopic(topic);
}
diff --git a/pubsub/cloud-client/src/test/java/com/example/pubsub/QuickstartSampleIT.java b/pubsub/cloud-client/src/test/java/com/example/pubsub/QuickstartSampleIT.java
index 1f67b86a20d..d293cd30bb6 100644
--- a/pubsub/cloud-client/src/test/java/com/example/pubsub/QuickstartSampleIT.java
+++ b/pubsub/cloud-client/src/test/java/com/example/pubsub/QuickstartSampleIT.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import com.google.cloud.ServiceOptions;
import com.google.cloud.pubsub.spi.v1.PublisherClient;
import com.google.pubsub.v1.TopicName;
@@ -40,11 +41,11 @@ public class QuickstartSampleIT {
private ByteArrayOutputStream bout;
private PrintStream out;
- private String projectId;
- private void deleteTestTopic(String projectId) throws Exception {
+ private void deleteTestTopic() throws Exception {
try (PublisherClient publisherClient = PublisherClient.create()) {
- publisherClient.deleteTopic(TopicName.create(projectId, "my-new-topic"));
+ publisherClient.deleteTopic(
+ TopicName.create(ServiceOptions.getDefaultProjectId(), "my-new-topic"));
} catch (IOException e) {
System.err.println("Error deleting topic " + e.getMessage());
}
@@ -55,10 +56,8 @@ public void setUp() {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);
- projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
- assertThat(projectId).isNotNull();
try {
- deleteTestTopic(projectId);
+ deleteTestTopic();
} catch (Exception e) {
//empty catch block
}
@@ -67,12 +66,12 @@ public void setUp() {
@After
public void tearDown() throws Exception {
System.setOut(null);
- deleteTestTopic(projectId);
+ deleteTestTopic();
}
@Test
public void testQuickstart() throws Exception {
- QuickstartSample.main(projectId);
+ QuickstartSample.main();
String got = bout.toString();
assertThat(got).contains("my-new-topic created.");
}