node.js - Firebase 消息:应用程序/网络超时(发出请求时出错:超过 10000 毫秒的超时)
问题描述
我在节点 JS 服务器上使用 firebase 的管理 SDK。我注意到,一整批通知通常会在没有明显原因的情况下失败。它在大多数情况下都可以正常工作,并且突然之间,连续 20 条通知显示超时。
完整的错误信息是:
{
code: "app/network-timeout",
message: "Error while making request: timeout of 10000ms exceeded."
}
我使用的代码总结如下:
const admin = require('firebase-admin');
admin.initializeApp({
credential: [...],
databaseURL: 'https://[...].firebaseio.com'
});
const message = {
notification: {
title: "My title",
body: "My content"
},
token: token
}
admin.messaging().send(message)
.then((response) => {
// message sent with success (most of the time)
})
.catch((err) => {
// message error: timeout
})
我认为这可能与定价计划有关,因为我通常在使用有限的 firebase 功能时遇到这种故障,但消息在定价计划中显示为“免费”。无论如何,我都切换到火花,以防万一,我会监控任何变化。
我找不到任何人报告此类问题,知道为什么我使用Firebase Messaging随机超时?
解决方案
错误消息提示我您的服务器暂时无法访问 FCM 服务器。就是说超过了10秒的超时时间。如果您收到此错误消息,您应该重试 API 以发送消息。
网络问题确实时有发生,并且您的服务器和 Firebase 之间可能有十几个您无法控制的网络跃点。网络故障重试对于容错始终很重要。
推荐阅读
- linux - 如何在没有正确 root 权限的情况下查看自己的 docker 文件
- python-3.x - 从多个 URL 中提取数据帧,导出到一个 CSV
- identityserver4 - Blazor WASM + IdentityServer4 + 自定义用户存储
- assembly - 堆栈指针在 x86 系统上的工作原理
- android - React Native Fetch 命令在调试版本上返回 JSON,但不是发布版本
- vue.js - Nuxt.js/Axios 自签名证书错误
- r - 如何在 Shiny 的 daterange UI 中显示文本?
- node.js - 快速发布请求将我重定向到 json 页面,而不是显示成功或错误消息 toast
- c - 使用 libelf 在 ELF 文件中注入 .preinit_array 部分
- c# - 记住窗口设置(大小、位置、位置)并恢复,但到屏幕 1