1

Storm实时处理案例(1)

 2 years ago
source link: http://kangkona.github.io/storm-real-time-case-1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Storm实时处理案例(1)

4/Sep 2014

Job

在Storm里面,用水流来比作数据流真是再合适不过了。 raw数据源源不断地流向Spout,
Spout对流入的数据进行检查,如果是符合要求的数据(好比质检合格的水),则从流中截
出一个单位数据。

通常会对流入的数据源定好协议,比如一个单位数据的header是FAFB, tail是EAEB:

    while( true ) {
        while( true ) {
         first = is.readByte();
         if (first == (byte)0xFA) {
            second = is.readByte();
            if (second == (byte)0xFB) {
                break;
            }
         }
        }
    }

其实上段代码不够严谨,比如出现0xFA0xFA0xFB…这样的流,就可能会丢弃正常的流。
询问得知正文和头部是正交的, 暂时按下不表。

之后对截断的流进行基础性的检查,emit出去,交给Bolt处理。

Spout只管喷射出一个个截断的数据流,Bolt(螺栓)把自己拧在Spout的接口上, 对输出
的元组进行必要的处理。

Storm的一大卖点是高度的稳定性,所以往往异常处理代码量比正常逻辑代码要多很多。

BTW, 看到这样一个段子:每条原始的Unix命令,都会变成一项互联网服务:

    find -> yahool!,
    grep->Google, 
    rsync->Dropbox, 
    man->stack overflow, 
    MapReduce = grep|sort|uniq,
    cron->ifttt,
    cp->Tencent, 
    trap->360, 
    wall->weibo.

其实Storm不正是对应着Pipe吗:)

More Reading

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK