Storm common mode-basicbolt

Source: Internet
Author: User

Many bolts in storm have one of the most common processing steps:

    1. Read a tuple;
    2. Based on this input tuple, after extraction, 0, 1 or more tuple are emitted;
    3. Finally, the ACK operation is used to confirm that the tuple is successfully processed.

Follow these steps to process the tuple tuples sent to the bolt in sequence.

This mode can implement simple functions or filter functions such as ETL. Storm encapsulates the corresponding interface ibasicbolt for this mode. Basebasicbolt and other classes implement this interface.

The following is based on basebasicbolt, which implements word frequency statistics based on the above pattern (CodeReference link: Storm-starter ):

 Public   Static   Class Wordcount Extends  Basebasicbolt {  //  Record the number of times each word and word appears Map <string, integer> counts =New Hashmap <string, integer> (); @ Override  Public   Void  Execute (tuple, basicoutputcollector collector) {string word = Tuple. getstring (0 ); Integer count = Counts. Get (Word ); //  Number of times a word appears              If (COUNT = Null  ) Count = 0 ; Count ++; Counts. Put (word, count );  //  Number of times a word appears to be updated Collector. emit ( New Values (word, count )); //  Emission Statistics  } @ Override  Public   Void  Declareoutputfields (outputfieldsdeclarer declarer) {declarer. Declare (  New Fields ("Word", "Count" ));}} 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.