我创建了一个node.js服务器来发送FCM消息。该服务器每天快速发送约50-70条不同的消息到不同的主题。有时候我会获得成功并得到一条消息,但主要是我收到了这个错误:
Error sending message: { Error: fcm.googleapis.com network timeout. Please try again.
at FirebaseAppError.Error (native)
at FirebaseAppError.FirebaseError [as constructor] (/ceciplan-server/node_modules/firebase-admin/lib/utils/error.js:39:28)
at new FirebaseAppError (/ceciplan-server/node_modules/firebase-admin/lib/utils/error.js:84:23)
at TLSSocket.<anonymous> (/ceciplan-server/node_modules/firebase-admin/lib/utils/api-request.js:121:51)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket.Socket._onTimeout (net.js:338:8)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
errorInfo:
{ code: 'app/network-timeout',
message: 'fcm.googleapis.com network timeout. Please try again.' } }
我的职能是:
function sendFCMMessage(fcmTitle, fcmBody, fcmTopic) {
var payload = {
notification: {
title: fcmTitle,
body: fcmBody
}
};
admin.messaging().sendToTopic(fcmTopic, payload).then(response => {
console.log(new Date().toUTCString(), "Successfully sent message:", response);
})
.catch(error => {
console.error(new Date().toUTCString(), "Error sending message:", error);
});
}
该函数由Firebase数据库快照子项的迭代调用,如下所示:
myRef.on("value", snapshot => {
snapshot.forEach(function (childSnapshot){
sendFCMMessage("Hello", "World", "myTopic")
});
});