nodejs-pubsub icon indicating copy to clipboard operation
nodejs-pubsub copied to clipboard

calling setOptions on subscriber does not take effect

Open dermasmid opened this issue 1 year ago • 5 comments

if changing flowControl settings after calling .on they dont not get into effect

const subscription = pubSubClient.subscription(subscriptionNameOrId);
const messageHandler = message => {

  message.ack();
};

subscription.on('message', messageHandler);

// does not have any effect on flow control
subscription.setOptions({
flowControl: {
          maxMessages: 1,
          allowExcessMessages: true,
 }
})

dermasmid avatar Feb 04 '24 20:02 dermasmid

I was able to confirm the bug by testing the client with a local script.

swarmiakimmo avatar Mar 15 '24 06:03 swarmiakimmo

Looks like it's not passing it down to the streaming pull subscriber stream. I'll verify what we want this to do, behaviour-wise.

feywind avatar Jun 13 '24 17:06 feywind

Have the same issue. maxMessages doesn't work for me when using streaming pulls. Any alternative till this is fixed or would we have to do unary pulls?

theabhinavdas avatar Jul 03 '24 10:07 theabhinavdas

@feywind What's also quite peculiar is that when I use options with subscriptions, it seems to square the number of maxMessages specified. For me, if I set this to 1, it does in fact seem to pull only one message (as noticed in my handler). When I set maxMessages to 2, it seems to pull 4 messages. When I set maxMessages to 3, it seems to pull 9 messages!

const subscription = pubSubClient.subscription(subscriptionNameOrId, {
    flowControl: {
      maxMessages: 1
    }
});

theabhinavdas avatar Jul 03 '24 11:07 theabhinavdas

@dermasmid from this other issue, it seems setting allowExcessMessages: false in your options fixes the issue like so:

const subscription = pubSubClient.subscription(subscriptionNameOrId, {
    flowControl: {
      maxMessages: 1,
      allowExcessMessages: false
    }
});

It may additionally have something to do with you instantly ack-ing in your messageHandler where you'd expect StreamingPull to pull the next message?

theabhinavdas avatar Jul 03 '24 11:07 theabhinavdas