const projectId = 'project-id'
const pubSubClient = new PubSub({ projectId });
const subscriptionNameOrId =

async function pubsubReview() {
  try {
    const [subs] = await pubSubClient.getSubscriptions();
    subs.forEach((s) => console.log(;

    const subscription = pubSubClient.subscription(subscriptionNameOrId);

    // Receive callbacks for new messages on the subscription
    subscription.on("message", async (message) => {
      await message.ackWithResponse();
      console.log("Received message:",;

    // Receive callbacks for errors on the subscription
    subscription.on("error", (error) => {
      console.error("Received error:", error);
  } catch (err) {
    console.log("nn", err, "nn");


I wrote this function to listen to new messages. I created notification with this configuration:
const updateMask = “notification_types,pubsub_topic”;
const projectID = “project-id”;
const topicName = topic-name;
const updateData = {
notificationTypes: [“NEW_REVIEW”, “UPDATED_REVIEW”],
pubsubTopic: projects/${projectID}/topics/${topicName},

i am getting notification messages on my listener, but very late. i am talking in hours. i am not sure why

I followed all steps as mentioned in Docs. Still cant figure out whats wrong. Also any code improvement suggestions i will appericiate.

New contributor

Sehej Wahla is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.