我正在建立一个发布金融工具价格的系统。一些仪器每秒更新几次,而其中一些更新频率较低。无论更新频率如何,所有订阅者都需要查看该工具的最后更新或当前价格。
订阅者可能会等待一段时间才能看到所有主题的主题更新,从而使他们对较慢主题的视图保持空白。我可以用 aSessionPropertiesListener
来收听新的听众,然后用当前价格更新每个主题,但这会给现有听众带来很多噪音,感觉就像尾巴在摇狗。
我可以用一个缓慢更新的主题来说明我的问题:
#!/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 秒才能看到任何内容。我觉得我在这里错过了一个技巧,如何确保订阅者在订阅后立即有效地获得当前价格?