1.促使写了此篇的理解点:
代码上:
worker1节点上:
worker2节点上:
从上面三张图看出来
topo的代码中prepare在各自进程开始调用,而两个节点产生了两个文件,说明nimbus给两个节点各自分发了一个jar包,开辟了jvm环境在各自的节点机器上执行,这是两个独立且联系的
进程
不要总是盯着主节点nimbus看运行情况什么的,忽略了工作节点supervisors,真正工作的是他们呀!!!
2.理解了kafka,zookeeper,storm的关系:
kafka
是一个消息队列MQ,是一个缓冲区.producer—>broker—>consumer
zookeeper
分布式集群统一管理,也可以看成一个文件系统树形结构的,可以create xxx,可以ls /xxx
storm
实时处理,不赘述
kafka的producer从flume(或者自己假装生产数据),然后push到broker,当consume(storm)需要了自己去pull。
这里提到Storm-kafka插件就是把storm的spout和kafka的consumer关联上,直接连上。
spout已经和kafka关联上了,不用自己定义spout,写了三个bolt,分别对过来的数据进行逻辑操作。
最后对写结果到本地的bolt代码分析下
public
void
prepare(Map
stormConf
, TopologyContext
context
, OutputCollector
collector
) {
this . collector = collector ;
try {
bf = new BufferedWriter( new FileWriter( new File( "/home/kang/" , "date.txt" ), true ));
} catch (IOException e ) {
// TODO Auto-generated catch block
e .printStackTrace();
}
}
@Override
public void execute(Tuple input ) {
List<Object> values = input .getValues();
String id = (String) values .get(0);
String memberid = (String) values .get(1);
String totalprice = (String) values .get(2);
String youhui = (String) values .get(3);
String sendpay = (String) values .get(4);
String createdate = (String) values .get(5);
double price = Double.parseDouble( totalprice );
double yh = Double.parseDouble( youhui );
double buy = price - yh ;
StringBuilder sb = new StringBuilder().append( "单号:" ).append( id ).append( "|" ).append( "用户id:" ).append( memberid )
.append( "|" ).append( "购买价格:" ).append(String.valueOf( buy ));
try {
bf .write( sb .toString());
bf .newLine();
bf .flush();
} catch (IOException e ) {
// TODO Auto-generated catch block
e .printStackTrace();
}
this . collector .ack( input );
this . collector = collector ;
try {
bf = new BufferedWriter( new FileWriter( new File( "/home/kang/" , "date.txt" ), true ));
} catch (IOException e ) {
// TODO Auto-generated catch block
e .printStackTrace();
}
}
@Override
public void execute(Tuple input ) {
List<Object> values = input .getValues();
String id = (String) values .get(0);
String memberid = (String) values .get(1);
String totalprice = (String) values .get(2);
String youhui = (String) values .get(3);
String sendpay = (String) values .get(4);
String createdate = (String) values .get(5);
double price = Double.parseDouble( totalprice );
double yh = Double.parseDouble( youhui );
double buy = price - yh ;
StringBuilder sb = new StringBuilder().append( "单号:" ).append( id ).append( "|" ).append( "用户id:" ).append( memberid )
.append( "|" ).append( "购买价格:" ).append(String.valueOf( buy ));
try {
bf .write( sb .toString());
bf .newLine();
bf .flush();
} catch (IOException e ) {
// TODO Auto-generated catch block
e .printStackTrace();
}
this . collector .ack( input );
}