gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 22:25:25 24 4
gpt4 key购买 nike

我使用以下代码进行 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.

这完全在意料之中。你说错误的订阅脚本,但它没有任何错误。除非您联网,否则什么都行不通。一旦您的应用离线,您希望应用如何接收消息?所以PubNub这里没有错误。它按预期工作。

建立连接,您将收到消息。

关于javascript - 异步发布和订阅消息在 pubnub 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47473035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com