Databases Reference
In-Depth Information
Shuffle Grouping
Shuffle Grouping is the most commonly used grouping. It takes a single parameter (the
source component) and sends each tuple emitted by the source to a randomly chosen
bolt warranting that each consumer will receive the same number of tuples.
The shuffle grouping is useful for doing atomic operations such as a math operation.
However, if the operation can't be randomically distributed, such as the example in
Chapter 2 where you needed to count words, you should consider the use of other
grouping.
Fields Grouping
Fields Grouping allows you to control how tuples are sent to bolts, based on one or
more fields of the tuple. It guarantees that a given set of values for a combination of
fields is always sent to the same bolt. Coming back to the word count example, if you
group the stream by the word field, the word-normalizer bolt will always send tuples
with a given word to the same instance of the word-counter bolt.
...
builder . setBolt ( "word-counter" , new WordCounter (), 2 )
. fieldsGrouping ( "word-normalizer" , new Fields ( "word" ));
...
All fields set in the fields grouping must exist in the sources's field dec-
laration.
All Grouping
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 ).
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
}
 
Search WWH ::




Custom Search