异步发布和订阅消息在 pubnub 中不起作用

Asynchronous publish and subscribe messages is not working in pubnub

我正在使用以下代码进行 pubnub 连接。

pubnub = new PubNub({
    subscribeKey: "demo",
    publishKey: "demo",
        keepAlive: true,
})
pubnub.addListener({
    message: function(message){
        console.log(message.channel+' '+message.publisher+' '+message.message.name+' '+time)
},
    status: function(s) {
        console.log(s.category+" "+s.operation+" "+s.affectedChannels +" "+s.subscribedChannels +" "+s.affectedChannelGroups+" "+time+" "+s.message)
    }
 });
 pubnub.history(
 {
    //child0, new
    channel: 'child3',
    reverse: true,
    count: 10
 },
 function (status, response) {
    // console.log(response);
    console.log(response.messages);
 }
 );
 pubnub.subscribe({
     channels: ['child3'],
     // resubscribe and reconnect
     restore : true, 
     //callback: function(m){console.log(m)} ,
 });

我有两个 nodejs 脚本,一个用于发布,另一个用于订阅 pubnub 中的消息。

当订阅者在线时,它能够接收来自发布者的消息,但是当订阅者离线时,由于网络连接故障,它无法从发布者接收适当的消息,这是由于错误的订阅脚本。

请解决此问题。

PubNub 在线订阅与离线订阅

When the Subscriber is online, it is able to receive messages from the Publisher but when the Subscriber goes offline, it is unable to receive the appropriate message from the Publisher due to a faulty network connection, occurring due to an erroneous Subscribe Script.

这完全在意料之中。你说 erroneous subscribe script 但没有任何错误。除非您已连接,否则什么都不会起作用。一旦您的应用程序 离线 ,您希望该应用程序如何接收任何消息?所以 PubNub 没有错误。它正常工作。

连接后您会收到消息。