Skip to content

Commit b795ea7

Browse files
committed
Update PubSub sample.
1 parent 96f3d67 commit b795ea7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

appengine-java8/pubsub/src/main/java/com/example/appengine/pubsub/PubSubPublish.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.cloud.ServiceOptions;
2020
import com.google.cloud.pubsub.v1.Publisher;
2121
import com.google.protobuf.ByteString;
22+
import com.google.pubsub.v1.ProjectTopicName;
2223
import com.google.pubsub.v1.PubsubMessage;
2324
import com.google.pubsub.v1.TopicName;
2425
import java.io.IOException;
@@ -40,9 +41,11 @@ public void doPost(HttpServletRequest req, HttpServletResponse resp)
4041
String topicId = System.getenv("PUBSUB_TOPIC");
4142
// create a publisher on the topic
4243
if (publisher == null) {
43-
publisher = Publisher.defaultBuilder(
44-
TopicName.create(ServiceOptions.getDefaultProjectId(), topicId))
44+
ProjectTopicName topicName = ProjectTopicName.newBuilder()
45+
.setProject(ServiceOptions.getDefaultProjectId())
46+
.setTopic(topicId)
4547
.build();
48+
publisher = Publisher.newBuilder(topicName).build();
4649
}
4750
// construct a pubsub message from the payload
4851
final String payload = req.getParameter("payload");

0 commit comments

Comments
 (0)