storm-All grouping的应用场景1-发送信号量指令

来源:互联网 发布:淘宝商家注册流程 编辑:程序博客网 时间:2024/06/05 16:44

All Grouping

from the book:Getting-Started-With-Storm-Jonathan

All Grouping sends a single copy of each tuple to all instances of the receiving bolt.

This kind of grouping is used to send signals to bolts. For example, if you need to refresh a cache, you can send a refresh cache signal to all bolts. 

In the word-count example,you could use an all grouping to add the ability to clear the counter cache (see Topol-ogies Example).

将信号的所有tuple发送给所有接收者

用来发送信号量,如发送一个清除 cache的指令

//一个bold 两个输入源builder.setBolt("word-counter", new WordCounter(),2).fieldsGrouping("word-normalizer", new Fields("word")).allGrouping("signals-spout","signals"); 

在bold的execute中做如下判断

public void execute(Tuple input) {String str = null;try{if(input.getSourceStreamId().equals("signals")){str = input.getStringByField("action");  
if("refreshCache".equals(str))  counters.clear();}}catch (IllegalArgumentException e) {//Do nothing} 
原创粉丝点击