【问题标题】:How to send push notification to more than 10000 users using firebase in nodejs?如何在nodejs中使用firebase向10000多个用户发送推送通知?
【发布时间】:2019-03-23 04:28:15
【问题描述】:

如果我有超过 10k 个用户,并且我有一个令牌数组,我如何发送给所有用户?我尝试每次对数组 1000 个用户进行分块,将 1000 个用户推送到一个主题,然后从一个主题中删除用户(在一个循环中)。但它是假的。有人遇到这种情况吗?谢谢! 示例代码:

let registrationTokens =[
token1,
token2,...
token10000
]
let promises = [];

for (let i = 0; i < 10; i++) {
    promises.push(
        admin
            .messaging()
            .subscribeToTopic(registrationTokens, topic) // subscrible topic 
            .then(function(response) {
                // send message to topic
                admin
                    .messaging()
                    .send(message)
                    .then(response => {
                        // remove user from topic 
                        admin
                            .messaging()
                            .unsubscribeFromTopic(registrationTokens, topic);
                    })
                    .catch(error => {
                        console.log('Error sending message:', error);
                    });
            })
            .catch(function(error) {
                console.log('Error subscribing to topic:', error);
                console.log(error);
                return res.send(error);
            })
    );
}

Promise.all(promises);

【问题讨论】:

    标签: node.js firebase push-notification firebase-cloud-messaging


    【解决方案1】:

    主题适用于您的用户订阅以接收有关某个...主题的消息的用例。您在这里所拥有的似乎不是一个很好的主题用法。

    由于您已经拥有要将消息发送到的实例的设备令牌:

    1. 您可以调用 API 到 send a message to a specific device 10.000 次。
    2. 或者,您可以使用registration_ids 参数一次将legacy HTTP API to send downstream messaging 用于1000 个设备。

    【讨论】:

    【解决方案2】:

    您可以使用 Firebase Admin SDK 包上的“sendMulticast”向包含最多 500 个注册令牌的列表发送推送通知,请检查 firebase docucumentation 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2016-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      相关资源
      最近更新 更多