I have a topic, and subscriptions related to it with pub/sub.
I'd like to test my function locally through VSCode, especially the function that triggers when a message is posted on my topic.
export const onPubSubMessage = onMessagePublished("projects/"id-of-project"/topics/"my-topic", (event) => {
    console.log('Message received')
  const message = event.data?.message;
  if (!message) {
    console.log("No message received");
    return;
  }
  const data = message.data ? Buffer.from(message.data, "base64").toString() : "{}";
  
  console.log("Message reçu :", data);
});
I've applied this function, but I don't see anything in my console, it's never triggered. However, I do see my messages in my subscription.
I have launched my emulator with functions & pubsub, and I can see in my console that my pubsub function is initialized.
I start my emulator with this command :
npm run build:watch
And in an other terminal, this is the script that I launch to start my emulator :
npm run build && firebase emulators:start --only functions,pubsub
My others functions running on the same configuration works, I just have issues to receive the message published on my topic.
Does anyone know why this is? How can I fix it?
I have a topic, and subscriptions related to it with pub/sub.
I'd like to test my function locally through VSCode, especially the function that triggers when a message is posted on my topic.
export const onPubSubMessage = onMessagePublished("projects/"id-of-project"/topics/"my-topic", (event) => {
    console.log('Message received')
  const message = event.data?.message;
  if (!message) {
    console.log("No message received");
    return;
  }
  const data = message.data ? Buffer.from(message.data, "base64").toString() : "{}";
  
  console.log("Message reçu :", data);
});
I've applied this function, but I don't see anything in my console, it's never triggered. However, I do see my messages in my subscription.
I have launched my emulator with functions & pubsub, and I can see in my console that my pubsub function is initialized.
I start my emulator with this command :
npm run build:watch
And in an other terminal, this is the script that I launch to start my emulator :
npm run build && firebase emulators:start --only functions,pubsub
My others functions running on the same configuration works, I just have issues to receive the message published on my topic.
Does anyone know why this is? How can I fix it?
Since it’s working on other functions, few factors for this behavior could be, there is a mismatch in the topic name, a small difference can prohibit the trigger to execute, check for the case sensitivity or even a whitespace could make a difference. Same project ID is a must also, verify if you have the same on both .firebaserc file and Pub/Sub Trigger topic. Also, try to clear the cache of the emulator at your firebase.

