Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the details of Storm development?

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what are the details of Storm development". In daily operation, I believe many people have doubts about what the details of Storm development are. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what are the details of Storm development?" Next, please follow the editor to study!

Package test;import java.io.IOException;import java.util.Map;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import storm.copyFromClass.TestWordSpout;import com.esotericsoftware.minlog.Log;import backtype.storm.Config;import backtype.storm.LocalCluster;import backtype.storm.task.OutputCollector;import backtype.storm.task.TopologyContext;import backtype.storm.topology.BasicOutputCollector;import backtype.storm.topology.OutputFieldsDeclarer;import backtype.storm.topology.TopologyBuilder;import backtype.storm.topology.base.BaseBasicBolt;import backtype.storm.topology.base.BaseRichBolt For the purpose of import backtype.storm.tuple.Tuple;// testing, here we need to test the current Spout data generation process public class testWordSpoutTopology {public static class TestSimpleBolt extends BaseBasicBolt {@ Override public void execute (Tuple input, BasicOutputCollector collector) {System.out.println (input.toString ()) } @ Override public void declareOutputFields (OutputFieldsDeclarer declarer) {System.out.println ("Method declare") }} public static void main (String [] args) throws IOException {/ / first, we must create a new TopologyBuilder TopologyBuilder builder = new TopologyBuilder () / / secondly, we need to configure the following components: 1 Spout,2Bolt builder.setSpout ("word-emit-byThread", new TestWordSpout ()) / / in this Spout, we agreed to shuffleGrouping builder.setBolt ("word-show", new TestSimpleBolt ()) .shuffleGrouping ("word-emit-byThread"); Config config = new Config () the meta-ancestor of [word-emit-byThread] Spout component. Config.setDebug (false); / / finally, local submission LocalCluster cluster = new LocalCluster (); cluster.submitTopology ("simple", config, builder.createTopology ());}}

Above

TestWordSpoutTopology

Is the main class that we run.

Package storm.copyFromClass;import backtype.storm.Config;import backtype.storm.topology.OutputFieldsDeclarer;import java.util.Map;import backtype.storm.spout.SpoutOutputCollector;import backtype.storm.task.TopologyContext;import backtype.storm.topology.base.BaseRichSpout;import backtype.storm.tuple.Fields;import backtype.storm.tuple.Values;import backtype.storm.utils.Utils;import java.util.HashMap;import java.util.Random;import org.slf4j.Logger;import org.slf4j.LoggerFactory / / public class TestWordSpout extends BaseRichSpout {public static Logger LOG = LoggerFactory.getLogger (TestWordSpout.class); boolean _ isDistributed; SpoutOutputCollector _ collector; public TestWordSpout () {this (true);} public TestWordSpout (boolean isDistributed) {_ isDistributed = isDistributed;} public void open (Map conf, TopologyContext context, SpoutOutputCollector collector) {_ collector = collector } public void close () {} / / send public void nextTuple () {Utils.sleep (100); final String [] words = new String [] {"Zhang Bing", "Angkor", "Tong Zhiwei", "predecessor", "Zen Master"}; final Random rand = new Random () Final String word = words [Rand.nextInt (words.length)]; _ collector.emit (new Values (word));} / / here, we did not do ACK public void ack (Object msgId) {} / / here, we did not do fail public void fail (Object msgId) {} public void declareOutputFields (OutputFieldsDeclarer declarer) {declarer.declare (new Fields ("word")) } @ Override public Map getComponentConfiguration () {if (! _ isDistributed) {Map ret = new HashMap (); ret.put (Config.TOPOLOGY_MAX_TASK_PARALLELISM, 1); return ret;} else {return null;}

Results:

Notice here that the default id for our Stream is empty

At this point, the study of "what are the details of Storm development" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report