1
votes

Happy May 1st,

I'm doing a simple POC to utilize the dead letter topic feature of PusSub. I configured my subscription to republish messages to a separate dead letter topic after 20 Maximum delivery attempts (below is the subscription pull code and sample message used). Dead letter topic configuration Note: I configured the subscription using Cloud Console.

Problem/challenge: Even after 36 delivery attempts the test message is still not republished to the dead letter topic. Based on the documentation I would assume my test message will be republished to the dead letter topic and shouldn't be delivered after 20 attempts. What am I missing? 36 attempts even after I nack everytime

Pull Subscription code

const {PubSub} = require('@google-cloud/pubsub');
var moment = require('moment');  

process.env['GOOGLE_APPLICATION_CREDENTIALS'] = 'abcxyz.json';

const pubSubClient = new PubSub();
const timeout = 100;

async function listenWithCustomAttributes() {
  const subscription = pubSubClient.subscription("projects/random-1234/subscriptions/testsub");
  
  // Create an event handler to handle messages
  const messageHandler = (message) => {

    const datetime = moment().format('mmmm do yyyy, h:mm:ss a');
    console.log(`${datetime}::: ${message.id}:`);
    console.log(`${message.data}`);
    console.log(`Delivery Attempt: ${message.deliveryAttempt}`);
    console.log(`custom Attributes: ${JSON.stringify(message.attributes)}`);
    console.log('\n');

    //NACK for re-delivery
    message.nack();
  };

  subscription.on('message', messageHandler);
  setTimeout(() => {
    subscription.removeListener('message', messageHandler);
  }, timeout * 1000000);
}

listenWithCustomAttributes();

Sample PubSub message

const message   = {
    "event": "First",
    "message": "HELLOWORLD!!!!",
};
1

1 Answers

1
votes

I finally was able to address this issue.

According to documentation "If you configured the subscription using Cloud Console, the roles are granted automatically." But, that no longer seems valid. We need to grant the required publisher & subscriber role in "DEAD LETTERING" (beside OVERVIEW) in the console of the subscription or add iam policy as described in the docs. enter image description here