Skip to content

Commit

Permalink
Update PubSub sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtisvg committed Mar 1, 2018
1 parent 96f3d67 commit b795ea7
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit b795ea7

Please sign in to comment.