From b795ea704edb98a31ea97415f4559060860f1243 Mon Sep 17 00:00:00 2001 From: Kurtis Van Gent Date: Thu, 1 Mar 2018 13:53:06 -0800 Subject: [PATCH] Update PubSub sample. --- .../java/com/example/appengine/pubsub/PubSubPublish.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/appengine-java8/pubsub/src/main/java/com/example/appengine/pubsub/PubSubPublish.java b/appengine-java8/pubsub/src/main/java/com/example/appengine/pubsub/PubSubPublish.java index bcf19d66b49..2ef35c03972 100644 --- a/appengine-java8/pubsub/src/main/java/com/example/appengine/pubsub/PubSubPublish.java +++ b/appengine-java8/pubsub/src/main/java/com/example/appengine/pubsub/PubSubPublish.java @@ -19,6 +19,7 @@ import com.google.cloud.ServiceOptions; import com.google.cloud.pubsub.v1.Publisher; import com.google.protobuf.ByteString; +import com.google.pubsub.v1.ProjectTopicName; import com.google.pubsub.v1.PubsubMessage; import com.google.pubsub.v1.TopicName; import java.io.IOException; @@ -40,9 +41,11 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp) String topicId = System.getenv("PUBSUB_TOPIC"); // create a publisher on the topic if (publisher == null) { - publisher = Publisher.defaultBuilder( - TopicName.create(ServiceOptions.getDefaultProjectId(), topicId)) + ProjectTopicName topicName = ProjectTopicName.newBuilder() + .setProject(ServiceOptions.getDefaultProjectId()) + .setTopic(topicId) .build(); + publisher = Publisher.newBuilder(topicName).build(); } // construct a pubsub message from the payload final String payload = req.getParameter("payload");