From 87129da0cf32794b46f952d994308d3f87118cc4 Mon Sep 17 00:00:00 2001 From: Alex Hong <9397363+hongalex@users.noreply.github.com> Date: Mon, 7 Dec 2020 15:44:18 -0800 Subject: [PATCH 1/2] switch ProjectTopicName to TopicName Fixes #570 --- .../background/util/BackgroundContextListener.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/background/src/main/java/com/getstarted/background/util/BackgroundContextListener.java b/background/src/main/java/com/getstarted/background/util/BackgroundContextListener.java index 753dcc674..7c2505b92 100644 --- a/background/src/main/java/com/getstarted/background/util/BackgroundContextListener.java +++ b/background/src/main/java/com/getstarted/background/util/BackgroundContextListener.java @@ -21,7 +21,7 @@ import com.google.cloud.pubsub.v1.Publisher; import com.google.cloud.translate.Translate; import com.google.cloud.translate.TranslateOptions; -import com.google.pubsub.v1.ProjectTopicName; +import com.google.pubsub.v1.TopicName; import java.io.IOException; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; @@ -52,17 +52,12 @@ public void contextInitialized(ServletContextEvent event) { event.getServletContext().setAttribute("translate", translate); } + TopicName topicName = TopicName.of(firestoreProjectId, topicId); Publisher publisher = (Publisher) event.getServletContext().getAttribute("publisher"); if (publisher == null) { try { String topicId = System.getenv("PUBSUB_TOPIC"); - publisher = - Publisher.newBuilder( - ProjectTopicName.newBuilder() - .setProject(firestoreProjectId) - .setTopic(topicId) - .build()) - .build(); + publisher = Publisher.newBuilder(topicName).build(); event.getServletContext().setAttribute("publisher", publisher); } catch (IOException e) { e.printStackTrace(); From 2a2f18250c1e1535dd2b1e5f80ab4fc975358850 Mon Sep 17 00:00:00 2001 From: Alex Hong <9397363+hongalex@users.noreply.github.com> Date: Mon, 7 Dec 2020 15:59:03 -0800 Subject: [PATCH 2/2] initialize topicId earlier --- .../getstarted/background/util/BackgroundContextListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background/src/main/java/com/getstarted/background/util/BackgroundContextListener.java b/background/src/main/java/com/getstarted/background/util/BackgroundContextListener.java index 7c2505b92..65bde106f 100644 --- a/background/src/main/java/com/getstarted/background/util/BackgroundContextListener.java +++ b/background/src/main/java/com/getstarted/background/util/BackgroundContextListener.java @@ -52,11 +52,11 @@ public void contextInitialized(ServletContextEvent event) { event.getServletContext().setAttribute("translate", translate); } + String topicId = System.getenv("PUBSUB_TOPIC"); TopicName topicName = TopicName.of(firestoreProjectId, topicId); Publisher publisher = (Publisher) event.getServletContext().getAttribute("publisher"); if (publisher == null) { try { - String topicId = System.getenv("PUBSUB_TOPIC"); publisher = Publisher.newBuilder(topicName).build(); event.getServletContext().setAttribute("publisher", publisher); } catch (IOException e) {