Storm Bolt Interface

Source: Internet
Author: User
Tags emit

Bolt is the basic unit of data processing in topology, and also a programming unit for the process of Storm . All the processing in the topology is done in these bolts. Bolts can send data items to multiple data streams (stream). Programmers can first declare multiple streams using the Declarestream () method of the Outputfieldsdeclarer class, specifying the stream to which the data will be sent. The data is then sent using the Spoutoutputcollector emit method (native spout).

Storm provides programming abstractions for bolts, in the form of interfaces, to interface-oriented programming styles. Where Irichbolt is the most important interface for implementing bolts using the Java language. In fact, Irichbolt itself does not provide more properties or methods, but expands (extends) the other two interfaces Ibolt and IComponent.

Irichbolt is the main interface for using the Java language to implement bolts, extending the extends of the other two interfaces Ibolt and IComponent. The interface contains a method that has prepare (in Stormconf,in context,in collector): Void,execute (in tuple): Void,cleanup (): void. The most important method is execute (), which receives a data item as input. Bolt can send the processed result as a new tuple, using the emit () method of the outputcollector object. Bolt can invoke the ACK () method on each of the sending data items in Outputcollector, allowing Storm to trace whether the data item is fully processed.

Ibolt and IComponent interfaces

1, prepare () and cleanup () void prepare (Java.util.map.stormconf,topologycontext context,outputcollector collector)

Prepare () A run-time task for instantiating a bolt that is called by a process in the cluster to provide the environment in which the bolt is running. Prepare () method three parameters: Stormconf,context,collector.

(1) The Sotrmconf object maintains the configuration information for the bolt in storm. These configuration information is provided by topology and is used by the machine running the bolt in the cluster.

(2) Contextual context object that gets information about the component's run-time task.

(3) The Collector object is used to send data items from this bolt.

2. Execute ()

This method is used for bolts to receive a data item (Tuple) from topology and can send the result of processing as a new data item (emit), which is the most important method that Bolt needs to implement. The parameter of this method, input, is a data item object that contains a large number of metadata (metadata), including its components, streams, tasks, and so on. The value in the data item can be obtained through the GetValue () method of the tuple class . The processing result is sent by calling the emit method implementation through the Outputcollector object provided in the prepare () method.

3, Ibasicbolt and Basebasicbolt

In many scenarios, the processing of bolts requires confirmation that the processing is complete or fails to determine. Requires code to emit data and call Ack/fail. Storm provides another interface Ibasicbolt for implementing the bolt, which is used for the implementation class of the interface, which automatically calls the Ack method after executing the Execute method.

  

Storm Bolt Interface

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.