Get the App
SLTechnology News&Howtos  ›  Servers  › 

How do you define storm drpc?

Shulou Source: shulou.com Published: 2022-05-31 17:16:46 09月22日 Update

This article introduces the relevant knowledge of "how to define storm drpc". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

Code:

package main.java;import main.java.bolt.RequestCounter;import backtype.storm.Config;import backtype.storm.LocalCluster;import backtype.storm.LocalDRPC;import backtype.storm.StormSubmitter;import backtype.storm.drpc.LinearDRPCTopologyBuilder;import backtype.storm.utils.DRPCClient;/** * DRPC example * * @author sjyu * */public class DRPCTopologyMain { public static void main(String[] args) throws Exception {// LocalDRPC drpc = new LocalDRPC(); DRPCClient drpc = new DRPCClient("192.168.1.240", 3772); LinearDRPCTopologyBuilder builder = new LinearDRPCTopologyBuilder("test_func"); builder.addBolt(new RequestCounter(), 2); Config conf = new Config(); conf.setDebug(true); StormSubmitter.submitTopology("drpc_test", conf, builder.createRemoteTopology());// LocalCluster cluster = new LocalCluster();// cluster.submitTopology("local_cluster", conf, builder.createLocalTopology(drpc)); String str = drpc.execute("test_func", "this is a test"); //client and server of drpc are written together here. I wonder if they can be written in two processes. //Imagination should be fine, just like network programming, but it has yet to be verified. System.out.println(str); }}package main.java.bolt;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 RequestCounter extends BaseBasicBolt {// Object id = new Object(); It seems that a variable cannot be defined here, otherwise an error will be reported,// I don't know if it's storm or java that can't be done (I think I need to learn java- -) @Override public void execute(Tuple input, BasicOutputCollector collector) { String str = (String) input.getString(1); collector.emit(new Values(input.getValue(0), str)); } @Override public void declareOutputFields(OutputFieldsDeclarer declarer) { declarer.declare(new Fields("id","result")); {}}"storm drpc how to define" the content of the introduction here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Content more knowledge no practical but not learning next two code reason variable dilemma actual situation article case editor website network Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Tech Info Huawei Shulou Technology macOS