storm学习

tuple 是bolt之间传递的变量

spout 的构成

ispout spout 功能

icomponent bolt 和 spout 公用配置和输出


spout中变量:

private SpoutOutputCollector outputCollector; 传送tuple

    
    
public void declareOutputFields(OutputFieldsDeclarer declarer) 
        
        
{declarer.declare(new Fields("commit"));} 定义输出的field

            
            
@Override
public void nextTuple() {
  for (String commit : commits) {
    outputCollector.emit(new Values(commit));

}} 

读取和处理tuple

            
            
public void open(Map configMap,
                 TopologyContext context,
                 SpoutOutputCollector outputCollector) {
  this.outputCollector = outputCollector;
  try {
    commits = IOUtils.readLines(
       ClassLoader.getSystemResourceAsStream("changelog.txt"),

Implementing a GitHub commit count dashboard in Storm

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
  declarer.declare(new Fields("commit"));}


                
                
public void open(Map configMap,
                 TopologyContext context,
                 SpoutOutputCollector outputCollector) {
  this.outputCollector = outputCollector;

       Charset.defaultCharset().name()
    );
  } catch (IOException e) {
    throw new RuntimeException(e);

}} 

读取之前的初始化



bolt构成中, IbasicBolt 是IRichBolt功能的子集


            
            
 @Override
  public void declareOutputFields(OutputFieldsDeclarer declarer) {
    declarer.declare(new Fields("email"));  声明输出
@Override
public void execute(Tuple tuple,
                  BasicOutputCollector outputCollector) {
String commit = tuple.getStringByField("commit");
String[] parts = commit.split(" ");
outputCollector.emit(new Values(parts[1]));

ticktuple 配置一段时间后发射一次。
配置:
            
            
@Override
public Map<String, Object> getComponentConfiguration() {
  Config conf = new Config();
  conf.put(Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS, 60);
  return conf;


例如:

@Override
public void execute(Tuple tuple,
                    BasicOutputCollector outputCollector) {
  if (isTickTuple(tuple)) {
    emitHeatmap(outputCollector);
  } else {

If we got atick tuple,interpret thatas a signal tosee whetherthere are anyheat mapsthat can beemitted.

For all timeintervalswe’recurrentlykeepingtrack of:if they ’veelapsed,removethemfrom thein-memorydatastructureand emitthem.

    Long time = tuple.getLongByField("time");
    LatLng geocode = (LatLng) tuple.getValueByField("geocode");
    Long timeInterval = selectTimeInterval(time);
    List<LatLng> checkins = getCheckinsForInterval(timeInterval);
    checkins.add(geocode);

}

private void emitHeatmap(BasicOutputCollector outputCollector) {
  Long now = System.currentTimeMillis();
  Long emitUpToTimeInterval = selectTimeInterval(now);
  Set<Long> timeIntervalsAvailable = heatmaps.keySet();

}

for (Long timeInterval : timeIntervalsAvailable) {
  if (timeInterval <= emitUpToTimeInterval) {
List<LatLng> hotzones = heatmaps.remove(timeInterval);
outputCollector.emit(new Values(timeInterval, hotzones));

}}

private Long selectTimeInterval(Long time) {
  return time / (15 * 1000);


An executor is a thread of execution within aJVM

A task isan instance of a spout or bolt running within that thread of execution. 

Each JVM can berunning one or moreexecutors (threads)of execution. 

A worker node has a JVM thatexecutes the logic in the spoutsand bolts for a topology. 

 builder.setBolt("geocode-lookup", new GeocodeLookup(), 8).setNumTasks(64)

Now we have 64 tasks (instances) of GeocodeLookup running across eight executors(threads). 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值