Home > OS >  Google Cloud PubSub not resending unacknowledged messages
Google Cloud PubSub not resending unacknowledged messages

Time:12-25

The selected answer for enter image description here

and the following code:

const subscription = this.pubSubClient
  .topic(this.topicName)
  .subscription(this.subscriptionName)

subscription.on('message', (message: Message) => {
  this.logger.verbose('Received message:', message.data.toString())
})

subscription.on('error', error => {
  this.logger.error('Received error:', error)
})

Messages published to the corresponding topic are logged from the code above as expected, however, they are not being resent, even though I'm not acknowledging them within the configured Acknowledgement deadline (or at all).

The Metrics Explorer correctly shows the unacknowledged messages:

enter image description here

Furthermore, when I explicitly call .nack() on the messages, they are resent, as expected.

Am I misunderstanding something?

CodePudding user response:

I believe that the client library that I'm using, @google-cloud/pubsub, automatically extends the acknowledgement deadline. With the following changes, I'm able to override that behavior, and the messages are indeed resent after the original acknowledgement deadline:

const flowControl: FlowControlOptions = {
  maxExtensionMinutes: 0,
}
const subscription = this.pubSubClient
  .topic(this.topicName)
  .subscription(this.subscriptionName, { flowControl: flowControl })

subscription.on('message', (message: Message) => {
  this.logger.verbose('Received message:', message.data.toString())
})

subscription.on('error', error => {
  this.logger.error('Received error:', error)
})

CodePudding user response:

For the nodejs-pubsub library, maxExtensionMinutes is the maximum duration to extend the message deadline before redelivering. There is a closed issue regarding this parameter, just in case you find it useful.

You can use the modifyAckDeadline parameter to extend the acknowledgement deadline (Dealing with duplicates and forcing retries).

From the PubSub side, PubSub guarantees At-Least-Once delivery, there are two exceptions that you might find useful (from documentation):

  • A message that cannot be delivered within the configured message retention duration is deleted and is no longer accessible. This typically happens when subscribers do not keep up with the flow of messages. See Replaying and purging messages for more information about the message retention settings.
  • A message published before a given subscription was created will usually not be delivered for that subscription. Thus, a message published to a topic that has no subscription will not be delivered to any subscriber.
  • Related