publish-subscribe – PubNub到服务器数据传输

我正在构建一个物联网应用程序.我正在使用PubNub在harware和用户之间进行通信.

现在,我需要将来自硬件和用户的所有消息和数据存储在中央服务器中.我们想做一些机器学习.

有没有办法做到这一点,除了让服务器订阅所有输出通道(将有很多它们)?

我希望某种一天一次的数据转储涉及PubNub中的存储和回放模块

提前致谢

最佳答案 PubNub到服务器数据传输

是的,您可以执行涉及存储和回放功能的每日一次的数据转储.

But first check this out! You can subscribe to Wildcard Channels like a.* and a.b.* to receive all messages in the hierarchy below. That way you can receive messages on all channels if you prefix each channel with a root channel like: root.chan_1 and root.chan_2. Now you can subscribe to root.* and receive all messages in the root.

要启用涉及存储和回放的每日一次数据转储,请先在您的帐户上启用Storage and Playback. PubNub会将您的所有消息存储在多个数据中心的磁盘上,以提高可靠性和读取延迟性能.最后,只要您知道要获取的通道,就可以使用服务器上的History API来获取存储的所有数据.

这是一个JavaScript函数,它将从通道中获取所有消息.

获取所有邮件用法

get_all_history({
    limit    : 1000,
    channel  : "my_channel_here",
    error    : function(e) { },
    callback : function(messages) {
        console.log(messages);
    }
});

获取所有消息代码

function get_all_history(args) {
    var channel  = args['channel']
    ,   callback = args['callback']
    ,   limit    = +args['limit'] || 5000
    ,   start    = 0
    ,   count    = 100
    ,   history  = []
    ,   params   = {
            channel  : channel,
            count    : count,
            callback : function(messages) {
                var msgs = messages[0];
                start = messages[1];
                params.start = start;
                PUBNUB.each( msgs.reverse(), function(m) {history.push(m)} );
                callback(history);

                if (history.length >= limit) return;
                if (msgs.length < count)     return;

                count = 100;
                add_messages();
            },
            error : function(e) {
                log(  message_out, [ 'HISTORY ERROR', e ], '#FF2262' );
            }
        };

    add_messages();
    function add_messages() { pubnub.history(params) }
}
点赞