【问题标题】:Topic subscribers may get nothing until an update is published在发布更新之前,主题订阅者可能一无所获
【发布时间】:2016-04-04 10:50:53
【问题描述】:

我正在构建一个发布金融工具价格的系统。一些仪器每秒更新几次,而其中一些更新频率较低。无论更新频率如何,所有订阅者都需要查看该工具的最后更新或当前价格。

订阅者可能会等待一段时间才能看到所有主题的主题更新,从而使他们对较慢主题的视图保持空白。我可以使用SessionPropertiesListener 来收听新的听众成员,然后用当前价格更新每个主题,但这会为现有听众成员产生很多噪音,感觉就像尾巴在摇摆狗。

我可以用一个更新缓慢的主题来说明我的问题:

#!/usr/local/bin/node
var diffusion = require('diffusion');

const diffHost = "localhost";
const exampleTopic = "some/counter";

diffusion.connect({
    host : diffHost,
    port: 8080,
    secure: false,
    principal : 'admin',
    credentials : 'password',
}).then(function(session) {
    console.log('Connected to %s', diffHost);

    var count = 0;
    session.topics.add(exampleTopic).then(function(result) {
        console.log("Created %s", exampleTopic);
        setInterval(function() {
            session.topics.update(exampleTopic, ++count);
            console.log("Updated %s to %d", exampleTopic, count);
        }, 5000);
    }, function(error) {
        console.log('Topic add failed: ', error);
    });
});

订阅some/counter 的任何人平均要等待 2.5 秒才能看到任何内容。我觉得我在这里错过了一个技巧,我怎样才能确保订阅者在订阅后立即有效地获得当前价格?

【问题讨论】:

    标签: push-diffusion


    【解决方案1】:

    您的主题some/counter 是无状态的,这就解释了为什么新订阅者在更新之前什么都没有收到。而不是创建您的主题:

    session.topics.add(exampleTopic)
    

    替换为:

    session.topics.add(exampleTopic, count)
    

    .. 创建一个有状态的ful主题。

    【讨论】:

      猜你喜欢
      • 2016-06-17
      • 1970-01-01
      • 1970-01-01
      • 2013-12-06
      • 1970-01-01
      • 2020-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多