Storm : Spout for reading data from a port

后端 未结 1 1975
情书的邮戳
情书的邮戳 2021-01-05 13:16

I need to write a storm spout for reading data from a port. Wanted to know if that was logically possible.

With that in mind, I had designed a simple topology design

相关标签:
1条回答
  • 2021-01-05 13:36

    In constructor just assign the variables. Try to instantiate ServerSocket in prepare method, do not write any new ... in constructor. And rename variables, you have two sc variables.

    public class ProxySpout extends BaseRichSpout{
    
        int port;
    
        public ProxySpout(int port){
            this.port=port;
        }
    
        @Override
        public void open(Map conf, TopologyContext context, SpoutOutputCollector collector)  { 
            //new ServerSocket
        }
    
        @Override
        public void nextTuple() {
    
        }
    
        @Override
        public void declareOutputFields(OutputFieldsDeclarer declarer) {
    
        }
    }
    

    If you put it in prepare method then it will only be called once the spout is already deployed, so it doesn't need to be serialized, and it will only be called once per lifetime of the spout, so it's not inefficient.

    0 讨论(0)
提交回复
热议问题