{"issue":{"created_at":"2011-12-06T08:56:27Z","state":"open","updated_at":"2011-12-06T08:56:27Z","user":{"gravatar_id":"2cbaa77d93c80e3831277ede824f616a","id":1079819,"url":"https://api.github.com/users/wangweichen","login":"wangweichen","avatar_url":"https://secure.gravatar.com/avatar/2cbaa77d93c80e3831277ede824f616a?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":0,"body":"spout:\r\n  public class RandomSentenceSpout implements IRichSpout {\r\n    SpoutOutputCollector _collector;\r\n    Random _rand;    \r\n    public static Logger LOG = Logger.getLogger(RandomSentenceSpout.class);\r\n    \r\n    \r\n    \r\n    public boolean isDistributed() {\r\n        return true;\r\n    }\r\n\r\n   \r\n    public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {\r\n        _collector = collector;\r\n        _rand = new Random();\r\n    }\r\n\r\n   \r\n    public void nextTuple() {\r\n        Utils.sleep(100);\r\n        String[] sentences = new String[] {\r\n            \"the cow jumped over the moon\",\r\n            \"an apple a day keeps the doctor away\",\r\n            \"four score and seven years ago\",\r\n            \"snow white and the seven dwarfs\",\r\n            \"i am at two with nature\"};\r\n        String sentence = sentences[_rand.nextInt(sentences.length)];\r\n        System.out.println(sentence);\r\n        _collector.emit(new Values(sentence));\r\n    }\r\n    \r\n    \r\n   \r\n    public void close() {        \r\n    }\r\n\r\n\r\n   \r\n    public void ack(Object id) {\r\n    }\r\n\r\n    \r\n    public void fail(Object id) {\r\n    }\r\n\r\n    \r\n    public void declareOutputFields(OutputFieldsDeclarer declarer) {\r\n        declarer.declare(new Fields(\"word\"));\r\n    }\r\n    \r\n}\r\n\r\n\r\nbolt:\r\n    package com.taobao.search.bolt.log;\r\n\r\nimport java.util.Map;\r\n\r\nimport org.apache.log4j.Logger;\r\n\r\nimport backtype.storm.task.OutputCollector;\r\nimport backtype.storm.task.TopologyContext;\r\nimport backtype.storm.topology.IRichBolt;\r\nimport backtype.storm.topology.OutputFieldsDeclarer;\r\nimport backtype.storm.tuple.Tuple;\r\n\r\npublic class RandmSentencebolt implements IRichBolt {\r\n\r\n\tpublic void prepare(Map stormConf, TopologyContext context,\r\n\t\t\tOutputCollector collector) {\r\n\t\t// TODO Auto-generated method stub\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic static Logger LOG = Logger.getLogger(RandmSentencebolt.class);\r\n\r\n\tpublic void execute(Tuple input) {\r\n\t\t// TODO Auto-generated method stub\r\n\t\tSystem.out.println(input);\r\n\t\tLOG.info(input);\r\n\t\t\r\n\t}\r\n\r\n\tpublic void cleanup() {\r\n\t\t// TODO Auto-generated method stub\r\n\t\t\r\n\t}\r\n\r\n\tpublic void declareOutputFields(OutputFieldsDeclarer declarer) {\r\n\t\t// TODO Auto-generated method stub\r\n\t\t///declarer.declare(new Fields(\"\"))\r\n\t\t\r\n\t}\r\n\t\r\n\r\n}\r\n\r\n\r\nmain function:\r\n    public class stormRun {\r\n   public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException, InterruptedException{\r\n\t   TopologyBuilder topbuilder = new TopologyBuilder();\r\n\t   topbuilder.setSpout(1,new RandomSentenceSpout(),5);\r\n\t  // topbuilder.setBolt(2, new bolthbase(), 5).fieldsGrouping(1, new Fields(\"word\"));\r\n\t   topbuilder.setBolt(2, new RandmSentencebolt(), 5).fieldsGrouping(1, new Fields(\"word\"));\r\n\t   Config conf = new Config();\r\n\t   conf.setDebug(true);\r\n\t   conf.setMaxTaskParallelism(10);\r\n\t   conf.setNumWorkers(10);\r\n\t   conf.setMaxSpoutPending(10);\r\n\t   StormSubmitter.submitTopology(\"stormtest\", conf, topbuilder.createTopology());\r\n\t   Thread.sleep(10000);\r\n\t   \r\n   }\r\n}\r\n\r\ni want to test spout to bolt !!!! bolt only print tuple!!!!\r\n\r\nplease help me to check code !!! \r\n\r\n\t   topbuilder.setSpout(1,new RandomSentenceSpout(),5);\r\n\t  // topbuilder.setBolt(2, new bolthbase(), 5).fieldsGrouping(1, new Fields(\"word\"));\r\n\t   topbuilder.setBolt(2, new RandmSentencebolt(), 5).fieldsGrouping(1, new Fields(\"word\"));\r\nthe code is right?\r\n","assignee":null,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"id":2459946,"number":66,"labels":[],"title":"help me !!check my simple code !tks!!!","html_url":"https://github.com/nathanmarz/storm/issues/66","closed_at":null,"url":"https://api.github.com/repos/nathanmarz/storm/issues/66","milestone":null},"action":"opened"}