简体   繁体   中英

PubSub Maximum delivery attempts & Dead letter topic

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). 死信主题配置 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 次尝试,即使在我每次都吃不饱之后

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,;!!", };

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. 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM