In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to use DRPC in Storm. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
1. Modify the storm.yaml configuration file of all nodes and set drpc server
[grid@hadoop6 ~] $vim storm-0.9.4/conf/storm.yamldrpc.servers:-"hadoop4"
two。 Start the drcp service
Storm drpc &
3. Write server programs
/ / from https://github.com/nathanmarz/storm-starter/blob/master/src/jvm/storm/starter/BasicDRPCTopology.javapackage storm.starter;import backtype.storm.Config;import backtype.storm.LocalCluster;import backtype.storm.LocalDRPC;import backtype.storm.StormSubmitter;import backtype.storm.drpc.LinearDRPCTopologyBuilder;import backtype.storm.topology.BasicOutputCollector;import backtype.storm.topology.OutputFieldsDeclarer;import backtype.storm.topology.base.BaseBasicBolt;import backtype.storm.tuple.Fields;import backtype.storm.tuple.Tuple;import backtype.storm.tuple.Values Public class BasicDRPCTopology {public static class ExclaimBolt extends BaseBasicBolt {@ Override public void execute (Tuple tuple, BasicOutputCollector collector) {String input = tuple.getString (1); collector.emit (new Values (tuple.getValue (0), input + "!");} @ Override public void declareOutputFields (OutputFieldsDeclarer declarer) {declarer.declare (new Fields ("id", "result")) } public static void main (String [] args) throws Exception {LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder ("exclamation"); builder.addBolt (new ExclaimBolt (), 3); Config conf = new Config (); if (args = = null | | args.length = = 0) {LocalDRPC drpc = new LocalDRPC (); LocalCluster cluster = new LocalCluster () Cluster.submitTopology ("drpc-demo", conf, builder.createLocalTopology (drpc)); for (String word: new String [] {"hello", "goodbye"}) {System.out.println ("Result for\"+ word +"\ ":" + drpc.execute ("exclamation", word));} cluster.shutdown (); drpc.shutdown () } else {conf.setNumWorkers (3); StormSubmitter.submitTopology (args [0], conf, builder.createRemoteTopology ();}
4. Package and submit the program to the Storm cluster
Storm jar Storm04-1.0-SNAPSHOT.jar storm.starter.BasicDRPCTopology exclamation
5. Write a client program to call the service remotely
Import backtype.storm.utils.DRPCClient;public class Client {public static void main (String [] args) throws Exception {DRPCClient client = new DRPCClient ("192.168.0.106", 3772); String [] words = {"hello", "storm", "drpc"}; for (String word: words) {String result = client.execute ("exclamation", word) System.out.println ("Result for\" + word + "\": "+ result);}}
6. The result of running the program:
After reading the above, do you have any further understanding of how to use DRPC in Storm? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.