storm拓扑不工作

6jjcrrmo  于 2021-06-21  发布在  Storm
关注(0)|答案(1)|浏览(299)

我是新的风暴,但我仍然在我的本地机器上配置风暴。我创建了一个eclipse项目,并遵循了一个来自internet的简单示例。现在我的拓扑正在提交,但它不工作。
拓扑是否已提交?是的,它被提交成功,因为我可以看到它在风暴用户界面。
我的拓扑学工作就是打印一个素数。但不是打印出来的。
我提供的代码如下:
喷口等级:

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" ) );
    }
}

螺栓等级:

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;
    }
}

拓扑类:

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();
        }
    }
}

现在我想问为什么不打印?或者为什么不写日志文件?
另外:我正在提交来自eclipse的拓扑。

bd1hkmkf

bd1hkmkf1#

除了什么 @Thomas Jungblut 说(关于log4j配置),并假设这是拓扑的完整源代码,然后看看您的 nextTuple() 你的嘴的方法。
你的嘴只不过是在释放一个值而已。很有可能您在控制台中丢失了该发射的输出,因为它埋在大量其他日志输出之下。
是否确定只发射一个值?

相关问题