3

I am using google pub sub in nodejs.
I have a service which publishes messages, and then a worker which listens to the messages and implements some processes on the messages.
Now I want my service to pull five subscription at a time and pull another one when it finished to process . How do I implement this?

Here is my start code how do I continue?

var pubsubClient = require('google-cloud').pubsub({
    projectId: 'my-project'
});

var topic = pubsubClient.topic('my-first-pub-sub');

var options = {
    reuseExisting: true,
    ackDeadlineSeconds: 90,
    autoAck: true,
    interval: 5000
};

topic.subscribe('MySub', options, function(err, subscription, apiResponse) {
    // Register listeners to start pulling for messages.
    function onError(err) {
        console.log("err", err);
    }
    function onMessage(message) {
        console.log("subscription", message);

    }
    // subscription.on('error', onError);
    // // subscription.on('message', onMessage);
    //
    var opts = {
        maxResults: 1
    };

    subscription.pull(opts, function(err, message) {
        console.log("subscription", err);
        console.log("subscription", message);
    });
});
dina
  • 4,039
  • 6
  • 39
  • 67
  • Is this operating in a Nodejs application on [App Engine](https://cloud.google.com/nodejs/)? What happens when you run this code and what did you expect to happen when running this code? Knowing a little more about what you've done and what results you received apart from just your code would help the community provide more specific and constructive answers to your question. – Nicholas Sep 28 '16 at 16:25

0 Answers0