Storm series: Create Maven project packages and submit wordcount to Storm cluster

Keywords: Java Apache git github

Links to the original text: http://www.cnblogs.com/NewIdea/p/deploy-wordcount-topology.html

In the last blog, we passed Storm.Net.Adapter Create a Storm Topology - word count written in Csharp. This article describes how to write Java-side programs and how to publish them to the Storm environment for testing.

If you find it helpful, welcome Star and Fork and let more people see them to help improve the project.

STEP1: Clone storm official sample project storm-starter:

 $ git clone git://github.com/apache/storm.git && cd storm/examples/storm-starter

STEP2: add multi language support for csharp:

Will be the last blog Create your first Storm topology using Cshare Project compilation completed in the project, copies the components produced into the / multilang/resources / folder.

STEP3: Create Topology with JAVA:

Add WordCountTopologyCsharp.java at / src/jvm/storm/starter/ New WordCountTopologyCsharp.java

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package storm.starter;

import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.StormSubmitter;
import backtype.storm.spout.ShellSpout;
import backtype.storm.task.ShellBolt;
import backtype.storm.topology.IRichBolt;
import backtype.storm.topology.IRichSpout;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.TopologyBuilder;
import backtype.storm.tuple.Fields;

import java.util.Map;

/**
 * This topology demonstrates Storm's stream groupings and multilang capabilities.
 */
public class WordCountTopologyCsharp {
    public static class Generator extends ShellSpout implements IRichSpout {

        public Generator() {
            super("cmd", "/k", "CALL", "StormSimple.exe", "generator");
            
        }

        @Override
        public void declareOutputFields(OutputFieldsDeclarer declarer) {
            declarer.declare(new Fields("word"));
        }

        @Override
        public Map<String, Object> getComponentConfiguration() {
            return null;
        }
    }    
    
    public static class Splitter extends ShellBolt implements IRichBolt {

        public Splitter() {
            super("cmd", "/k", "CALL", "StormSimple.exe", "splitter");
        }

        @Override
        public void declareOutputFields(OutputFieldsDeclarer declarer) {
            declarer.declare(new Fields("word", "count"));
        }

        @Override
        public Map<String, Object> getComponentConfiguration() {
            return null;
        }
    }
    
    public static class Counter extends ShellBolt implements IRichBolt {
        
        public Counter(){
            super("cmd", "/k", "CALL", "StormSimple.exe", "counter");
        }
        
        @Override
        public void declareOutputFields(OutputFieldsDeclarer declarer) {
            declarer.declare(new Fields("word", "count"));
        }

        @Override
        public Map<String, Object> getComponentConfiguration() {
            

Reprinted at: https://www.cnblogs.com/NewIdea/p/deploy-wordcount-topology.html

Posted by phynias on Fri, 11 Oct 2019 10:46:43 -0700