pubnub 订阅在一段时间后停止接收消息 [英] Pubnub subscribe stops receiving messages after some time

查看:50
本文介绍了pubnub 订阅在一段时间后停止接收消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些远程设备可以与运行在 Docker 容器中的 Digital Ocean Ubuntu 14.04 droplet 上的中央 Meteor 应用程序进行通信.每个设备都有自己的频道,服务器订阅所有频道以及所有设备共有的遥测"频道.一段时间内一切正常(几天到几周),但是只要有消息发送(消息显示在 PubNub 调试控制台中),服务器上的订阅回调就会停止触发.服务器可以正常发布.重新启动服务器后,订阅再次正常工作.这是相关的代码片段:

 pubnub = new PubNub({发布密钥:公钥",subscribeKey:子密钥"});pubnub.addListener({消息:功能(米){控制台日志(m.channel);控制台日志(m.message);控制台日志(m.timetoken);控制台日志(m.subscription);如果(m.channel ==遥测"){手柄遥测(米);} 别的 {处理请求(米);}},错误:函数(错误){//这里处理错误console.log(JSON.stringify(error));}});pubnub.subscribe({channel: chans//chans 是一个频道列表});

是否有某种默认超时停止订阅服务?如果是这样,我该如何禁用它?

查看参考我发现这个值可以传递给初始化,但我不确定它是否与我相关.

我现在正在我的开发服务器中运行一个测试,presenceTimeout 设置为 0 并且它正在工作,但是重新创建它是一个非常困难的问题,因为它可能需要很长时间才能弹出所以如果有人对此有任何见解问题将不胜感激.我会每周更新测试的进展情况.

现在我在生产中的临时修复是让 cron 每天重启服务器,这对我来说并不理想.

2/15/17 更新

在启用 Pubnub 调试日志的情况下进行了测试.它再次停止工作.下面是日志的最后几行.

心跳似乎正常.我在重新启动之前重新检查了日志,并且在 UTC 时间 6:44 记录了另一个日志.6:39 心跳后的对象是成功发布到我的设备之一的消息.有任何想法吗?

您可以在

I have some remote devices which communicate with a central Meteor application running on a Digital Ocean Ubuntu 14.04 droplet in a Docker container. Each device has it's own channel, and the server is subscribed to all the channels plus a "telemetry" channel common to all devices. Everything works fine for a while (a few days to a few weeks), but then the subscribe callback on the server stops firing whenever there's a message sent (the messages show up in the PubNub debug console). The server can publish normally though. The subscription works normally again after I restart the server. Here's the relevant code snippet:

 pubnub = new PubNub({
    publishKey: "pub-key",
    subscribeKey: "sub-key"
});
pubnub.addListener({
    message: function (m) {
        console.log(m.channel);
        console.log(m.message);
        console.log(m.timetoken);
        console.log(m.subscription);
        if (m.channel == "telemetry") {
            handleTelemetry(m);
        } else {
            handleRequest(m);
        }
    },
    error: function (error) {
        // Handle error here
        console.log(JSON.stringify(error));
    }
});

pubnub.subscribe({
    channels: chans //chans is a list of channels
});

Is there some sort of default timeout that stops a subscription service? If so how can I disable it?

Looking through the reference I found this value that I can pass to the initialization, but I'm not sure if it's relevant to me.

I'm running a test right now in my development server with presenceTimeout set to 0 and it's working, but it's a very hard problem to recreate as it can take a long time to pop up so if anyone has any insight into this problem it'll be appreciated. I'll update weekly on how the test is going.

Right now my temp fix in production is to have cron restart the server everyday which is not really ideal for me.

Update 2/15/17

Did a test with the Pubnub debugging logs enabled. It stopped working again. Below are the last few lines of the log.

The heartbeats seem to be coming in normally. I rechecked the logs before I restarted it and another one was recorded at 6:44 utc. The object after the heartbeat at 6:39 is a message that was successfully published to one of my devices. Any ideas?

You can see the full log here. The logs from my code aren't formatted very well so excuse the mess.

解决方案

Running NodeJS in Docker on Digital Ocean

With a PubNub Socket Connection to receive updates on data channels you can setup a node.js app which runs continuously. The following example is runnable from command line when you name your file app.js.

npm install pubnub

node app.js

// app.js

const PubNub = require('pubnub');
const pubnub = new PubNub({ publishKey : 'demo', subscribeKey : 'demo' });

pubnub.addListener({
    message  : m => console.log(m) 
,   error    : m => console.log(m) 
,   presence : m => console.log(m) 
});

pubnub.subscribe({ channels : ['a'] });

这篇关于pubnub 订阅在一段时间后停止接收消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆