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");