简体   繁体   中英

Storm Topology not working

I am new to storm but still i have configured storm on my local machine. I made an eclipse project and followed a simple example from internet. Now my topology is getting submitted but its not working.

Was topology submitted? Yeah it was submitted successfully as I can see it on storm ui.

Work of my topology is to just print a number if it is a prime number. But its not printing it.

I have provided my code as follows:

Spout Class:

public class NumberSpout extends BaseRichSpout 
{
    private SpoutOutputCollector collector;
    private static final Logger LOGGER = Logger.getLogger(SpoutOutputCollector.class);
    private static int currentNumber = 1;

    @Override
    public void open( Map conf, TopologyContext context, SpoutOutputCollector collector ) 
    {
        this.collector = collector;
    }

    @Override
    public void nextTuple() 
    {
        // Emit the next number
        LOGGER.info("Coming in spout tuble method");
        collector.emit( new Values( new Integer( currentNumber++ ) ) );
    }

    @Override
    public void ack(Object id) 
    {
    }

    @Override
    public void fail(Object id) 
    {
    }

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

Bolt Class:

public class PrimeNumberBolt extends BaseRichBolt 
{   private static final Logger LOGGER = Logger.getLogger(PrimeNumberBolt.class);
    private OutputCollector collector;

    public void prepare( Map conf, TopologyContext context, OutputCollector collector ) 
    {
        this.collector = collector;
    }

    public void execute( Tuple tuple ) 
    {
        int number = tuple.getInteger( 0 );
        if( isPrime( number) )
        {
            LOGGER.info("Prime number printed is: )" +number);
           System.out.println( number );
        }
        collector.ack( tuple );
    }

    public void declareOutputFields( OutputFieldsDeclarer declarer ) 
    {
        declarer.declare( new Fields( "number" ) );
    }   

    private boolean isPrime( int n ) 
    {
        if( n == 1 || n == 2 || n == 3 )
        {
            return true;
        }

        // Is n an even number?
        if( n % 2 == 0 )
        {
            return false;
        }

        //if not, then just check the odds
        for( int i=3; i*i<=n; i+=2 ) 
        {
            if( n % i == 0)
            {
                return false;
            }
        }
        return true;
    }
}

Topology Class:

public class PrimeNumberTopology 
{
    public static void main(String[] args) 
    {
        TopologyBuilder builder = new TopologyBuilder();
        builder.setSpout( "spout", new NumberSpout(),1 );
        builder.setBolt( "prime", new PrimeNumberBolt(),1 )
                .shuffleGrouping("spout");
        Config conf = new Config();
        conf.put(Config.NIMBUS_HOST, "127.0.0.1");
        conf.setDebug(true);
        Map storm_conf = Utils.readStormConfig();
        storm_conf.put("nimbus.host", "127.0.0.1");
        Client client = NimbusClient.getConfiguredClient(storm_conf)
                .getClient();
        String inputJar = "/home/jamil/Downloads/storm-twitter-word-count-master/target/storm-test-1.0-SNAPSHOT.jar";
        NimbusClient nimbus = new NimbusClient("127.0.0.1",6627);
        // upload topology jar to Cluster using StormSubmitter
        String uploadedJarLocation = StormSubmitter.submitJar(storm_conf,
                inputJar);
        try {
            String jsonConf = JSONValue.toJSONString(storm_conf);
            nimbus.getClient().submitTopology("newtesttopology",
                    uploadedJarLocation, jsonConf, builder.createTopology());
        } catch (AlreadyAliveException ae) {
            ae.printStackTrace();
        } catch (InvalidTopologyException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (TException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

Now I want to ask that why its not printing? Or why its not writing it to log files?

PLUS: I am submitting topology from eclipse.

In addition to what @Thomas Jungblut said (regarding your log4j configuration) and assuming that is the complete source code of your topology, then have a look at your nextTuple() method of your spout.
Your spout is simply emitting one value and thats it. Great chances that you are missing the output of that emitting in your console because it is buried under a ton of other logging outputs.
Are you sure that you want to emit just one value?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM