How to use PubSub to get one message at time

1.3k Views Asked by At

I need my onPublish method (firebase side) to get only one message at time.

My code is like this:

Google Cloud (AppEngine):

const pubsub = new PubSub({
  projectId: config.project,
});

const topicName = 'projects/'+config.project+'/topics/user_assigner';

const dataBuffer = Buffer.from(dataToSend);
  pubsub
    .topic(topicName)
    .publisher()
    .publish(dataBuffer, (err, messageId)=> {
      console.log("call back")
      console.log("err",err)
      console.log("messageId",messageId)
      resolve(messageId)
    })

Firebase

    var functions = require('firebase-functions');

    module.exports =
      functions.pubsub.topic('user_assigner').onPublish((event) => { 
          return someAsyncCode() //return promise;
      });

I need the code someAsyncCode to run messages one by one, is there a way to do that? I have seen on the documentation of the publisher the batch maxMessages but I think that is to set the limit when the publisher push new messages to the queue of messages. So, if I set that attibute to one is the same, the publisher will push one buy one(gcloud side), and the onPublish (firebase side) will get all the messages no matter if it is processing one.

0

There are 0 best solutions below