Google cloud platform 即使在获得HTTP 200/202/204后,google cloud pubsub push仍会继续重试

Google cloud platform 即使在获得HTTP 200/202/204后,google cloud pubsub push仍会继续重试,google-cloud-platform,google-cloud-pubsub,google-cloud-run,Google Cloud Platform,Google Cloud Pubsub,Google Cloud Run,我们使用GoogleCloudPubSub主题发布一条消息,该主题具有云运行推送订阅。云运行服务通过发送204/200,在收到消息后立即确认消息。 尽管确认,pubsub仍继续重试。此实现基于 是否有办法确保pubsub在确认后不会重试。我想知道解决这个问题的唯一方法是否是实现一个中间件并拒绝重复的消息 app.post('/deploy/environment',(req,res)=>{ 试一试{ 如果(!请求正文){ const msg=`未收到发布/订阅消息'; logger.error(

我们使用GoogleCloudPubSub主题发布一条消息,该主题具有云运行推送订阅。云运行服务通过发送204/200,在收到消息后立即确认消息。 尽管确认,pubsub仍继续重试。此实现基于

是否有办法确保pubsub在确认后不会重试。我想知道解决这个问题的唯一方法是否是实现一个中间件并拒绝重复的消息

app.post('/deploy/environment',(req,res)=>{
试一试{
如果(!请求正文){
const msg=`未收到发布/订阅消息';
logger.error(`error:${msg}`);
res.status(202).send(`Bad Request:${msg}`);
返回;
}
如果(!req.body.message | |!req.body.message.data){
const msg=`无效的发布/订阅消息格式';
logger.error(`error:${msg}`);
res.status(202).send(`Bad Request:${msg}`);
返回;
}
const dataUtf8encoded=Buffer.from(req.body.message.data,'base64')。toString('utf8');
info(`messagecontent:${dataUtf8encoded}`);
让内容;
试一试{
content=JSON.parse(dataUtf8encoded);
}捕获(ex){
warn('Bad request invalid JSON');
返回res.sendStatus(202);
}
如果(!content.environmentId){
const msg=`EnvironmentId是一个必需参数`;
logger.error(`error:${msg}`);
res.status(202).send(`Bad Request:${msg}`);
返回;
}如果(!content.environment){
const msg=`环境是一个必需参数';
logger.error(`error:${msg}`);
res.status(202).send(`Bad Request:${msg}`);
返回;
}else if(!content.roles){
const msg=`Roles是一个强制参数`;
logger.error(`error:${msg}`);
res.status(202).send(`Bad Request:${msg}`);
返回;
}
res.status(204.send();
runSystemPackage(content.environmentId、content.environment、content.roles);
}捕捉(错误){
logger.error(`error:${err.message}`);
res.status(202).send(`${err}`);
}
});
日志:


1) 你怎么知道一个200/204被退回?编辑您的问题并发布Stackdriver日志,显示正在调用的云运行服务。在我修复了编码错误之后,我已经在许多项目中实现了Pub/Sub和Cloud,并且没有出现任何问题。我看到的一个问题是runSystemPackage。对于调试,将PubSub订阅的“确认截止时间”更改为600秒。默认值为10秒。如果runSystemPackage花费的时间超过10秒,那就是你的问题。我添加了一些日志片段。如果您注意到我在调用runSystemPackage之前发送了一个204,正如我在日志中注意到的那样,当我等待它完成时,ACK被延迟了。在我的示例中没有发送任何东西的代码路径,除了HTTP2xx。我认为发布/订阅将继续重试。我现在使用600秒ack进行测试。您不能在runSystemPackage之前发送HTTP 204。当代码返回HTTP响应时,代码将不再执行。您假设204是在该代码行发送的。注意:消息之间不显示600秒的延迟。另外,不要截断日志。我需要查看HTTP请求/响应的开始和结束时间,而不是最终响应。我认为您是对的,将超时时间增加到600秒后,我没有看到重试。我怀疑res.status(204).send()的顺序无关紧要,它似乎在等待runSystemPackage完成。有很多日志我无法共享,因此被截断。谢谢
"2019-06-12T04:49:44.015789Z"  POST /deploy/environment 204 1ms 
"2019-06-12T04:49:44.014897Z"  Message content: {"environmentId": "5","environment": "pvs5", "roles": ["core"]} 
"2019-06-12T03:42:22.251890Z"  Message [object Promise] published. 

Snippet showing retries:
"2019-06-12T04:57:01.167608Z"  POST /deploy/environment 204 1ms 
"2019-06-12T04:56:43.233886Z"  POST /deploy/environment 204 39ms 
"2019-06-12T04:55:33.630202Z"  POST /deploy/environment 204 0ms 
"2019-06-12T04:55:12.609798Z"  POST /deploy/environment 204 0ms