Introduction to the basic concept of storm0.9.3

Source: Internet
Author: User
Tags emit

Welcome to: Ruchunli's work notes , learning is a faith that allows time to test the strength of persistence.


Brief introduction:

    storm is a real-time processing system developed by Backtype, with Clojure , Backtype is now under Twitter. Twitter contribute storm to the open source community, a distributed, fault-tolerant real-time computing system that is hosted on the github on, follow Eclipse public License 1.0.


Basic concepts:

There are some core basic concepts in storm, including topology, Nimbus, Supervisor, Worker, Executor, Task, Spout, Bolt, Tuple, Stream, stream grouping (grouping), and so on.



Getting Started example:

package storm;import java.util.map;import backtype.storm.config;import  backtype.storm.localcluster;import backtype.storm.spout.spoutoutputcollector;import  backtype.storm.task.outputcollector;import backtype.storm.task.topologycontext;import  backtype.storm.topology.outputfieldsdeclarer;import backtype.storm.topology.topologybuilder;import  backtype.storm.topology.base.baserichbolt;import backtype.storm.topology.base.baserichspout;import  backtype.storm.tuple.fields;import backtype.storm.tuple.tuple;import backtype.storm.tuple.values;/**  *  *  @author  lucl *  * */public class  localstormtopology {/** *  launch Data  *  @author  lucl * */public static  class DatasourceSpout extends BaseRichSpout {private Map conf =  Null;private topologycontext context = null;private spoutoutputcollector collector = null;int num = 0;/** *  dead Loop, always call  */ @Overridepublic  void nexttuple ()  {try {thread.sleep (1 * 1000);}  catch  (interruptedexception e)  {e.printstacktrace ();} if  (num % 2 == 0)  {system.out.println ("spout emission data (even): "  + num); This.collector.emit (New values ("even",  num));// values supports dynamic parameters} else { SYSTEM.OUT.PRINTLN ("Spout emission data (odd): "  + num) This.collector.emit (new values ("odd",  num));// values supports dynamic parameter}num += 1;} The/** *  initialization method, which is called once  */at topology initialization @Overridepublic  void open (map conf,  Topologycontext context, spoutoutputcollector collector)  {this.conf = conf; This.context = context;this.collector = collector;} /** * spout transmit data, bolt reads data, but how does bolt know how to parse the emitted data, it needs to declare  */in advance @Overridepublic void declareoutputfields (Outputfieldsdeclarer declarer)  {declarer.declare (new Fields ("type",  "num");  //  corresponds to the number of data and Num fields above}}/** *  *  @author  lucl *  data processing  */ public static class datasourcebolt extends baserichbolt {private map  conf = null;private topologycontext context;private outputcollector collector;/* * *  processing  */int even = 0;int odd = 0; @Overridepublic for spout data  void execute (tuple tuple)  {string type = tuple.getstringbyfield ("type"); Nteger value = tuple.getintegerbyfield ("num");if  ("even". Equals (type))  {even +=  value; System.out.println ("even (even) cumulative result of bolt processing:"  + even);}  else {odd += value; System.out.println ("even (odd) cumulative result of bolt processing:"  + odd);}} @Overridepublic  void prepare (Map&nbsP;conf, topologycontext context, outputcollector collector)  {this.conf =  Conf;this.context = context;this.collector = collector;} @Overridepublic  void declareoutputfields (outputfieldsdeclarer ceclarer)  { System.out.println ("method declareoutputfields of class bolt!"); /  if the bolt also needs to pass data to the next bolt for processing, it also needs to declare its output field}}/** *  *  @param  args */public  static void main (String[] args)  {//  in this topology, All spout and bolt IDs are not identical topologybuilder builder = new topologybuilder (); Builder.setspout (" Spout ",  new datasourcespout ()); Builder.setbolt (" Bolt ",  new datasourcebolt ()). Shufflegrouping ("spout");//  uses local mode to execute Localcluster cluster = new localcluster (); Cluster.submittopology ("Topology",  new config (),  builder.createtopology ());}}

The results of the operation are as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/74/9C/wKiom1YjrYDDG6mKAAF3ZOHhLII811.jpg "title=" Qq20151018223207.jpg "alt=" Wkiom1yjryddg6mkaaf3zohhlii811.jpg "/>

This article is from the "Ruchunli's work Notes" blog, so be sure to keep this source http://luchunli.blog.51cto.com/2368057/1704036

Introduction to the basic concept of storm0.9.3

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.