经典计算模型
数据流编程,由于网络规模的实时服务的激增,正在经历复兴。它固有的简单性,可扩展性和资源效率使其非常适合众多工程挑战。 Straw是一个Node.js框架,促进了数据流的实现,最初是为实时财务数据处理而设计的,并且能够在适度的硬件上每秒处理数千封消息。
稻草和干草概论>
。 干草堆克隆和设置: >运行FireHose数据流>
, )。访问
>
(无输入)引入消息;
>catch-langs节点(用于语言聚合)
使用express和socket.io(或sockjs)使用A )接收并可视化此数据。
Haystack 示例用于实时数据流的数据流处理。 Straw的固有的并行性和模块化简化了复杂的任务。 通过添加节点和可视化来扩展干草堆。>
npm install -g bower
<code class="language-bash">git clone https://github.com/simonswain/haystack
cd haystack
npm install
bower install</code>
consumer_key
,consumer_secret
。 用您的凭据更新Haystack的示例配置文件(access_token_key
):access_token_secret
>
config.js
<code class="language-javascript">exports.twitter = {
consumer_key: '{your consumer key}',
consumer_secret: '{your consumer secret}',
access_token_key: '{your access token key}',
access_token_secret: '{your access token secret}'
};</code>
),另一个用于Express Server(node run
。node server.js
的可视化
http://localhost:3000
run.js
<code class="language-javascript">var topo = new straw.topology({
'consume-firehose': {
'node': __dirname + '/nodes/consume-firehose.js',
'output': 'raw-tweets',
'twitter': config.twitter
},
'route-tweets': {
'node': __dirname + '/nodes/route-tweets.js',
'input': 'raw-tweets',
'outputs': {
'geo': 'client-geo',
'lang': 'lang',
'text': 'text'
}
},
// ... more nodes
});</code>
>目录中。 nodes
演示了选择性消息路由的多个输出。consume-firehose
route-tweets
>consume-firehose.js
<code class="language-javascript">// nodes/consume-firehose.js
var straw = require('straw');
var Twitter = require('twitter');
module.exports = straw.node.extend({
initialize: function(opts, done) {
this.twit = new Twitter(opts.twitter);
process.nextTick(done);
},
run: function(done) {
var self = this;
this.twit.stream('statuses/sample', function(stream) {
stream.on('data', function(data) {
self.output(data);
});
});
done(false);
}
});</code>
:
<code class="language-bash">git clone https://github.com/simonswain/haystack
cd haystack
npm install
bower install</code>
catch-langs
汇总语言计数,定期排放总计以避免压倒性的客户。 它使用setInterval
来控制发射,增加语言计数并在发生变化时发射总数。
server.js
>
straw.tap
public/js/haystack.js
结论
以上是用稻草编程数据流程的详细内容。更多信息请关注PHP中文网其他相关文章!