Max number of tuple replays on Storm Kafka Spout

前端 未结 5 1395
别跟我提以往
别跟我提以往 2021-01-17 17:34

We’re using Storm with the Kafka Spout. When we fail messages, we’d like to replay them, but in some cases bad data or code errors will cause messages to always fail a Bolt,

5条回答
  •  野的像风
    2021-01-17 18:25

    As per my knowledge Storm doesn't provide built-in support for this.

    I have applied below-mentioned implementation:

    public class AuditMessageWriter extends BaseBolt {
    
            private static final long serialVersionUID = 1L;
            Map failedTuple = new HashMap<>();
    
            public AuditMessageWriter() {
    
            }
    
            /**
             * {@inheritDoc}
             */
            @Override
            public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) {
                this.collector = collector;
                //any initialization if u want
            }
    
            /**
             * {@inheritDoc}
             */
            @Override
            public void execute(Tuple input) {
                try {
    
                //Write your processing logic
                collector.ack(input);
                } catch (Exception e2) {
                //In case of any exception save the tuple in failedTuple map with a count 1
                //Before adding the tuple in failedTuple map check the count and increase it and fail the tuple
    
                //if failure count reaches the limit (message reprocess limit) log that and remove from map and acknowledge the tuple
                log(input);
                ExceptionHandler.LogError(e2, "Message IO Exception");
                }
    
            }
    
            void log(Tuple input) {
    
                try {
                    //Here u can pass result to dead queue or log that
    //And ack the tuple 
                } catch (Exception e) {
                    ExceptionHandler.LogError(e, "Exception while logging");
                }
            }
    
            @Override
            public void cleanup() {
                // To declare output fields.Not required in this alert.
            }
    
            @Override
            public void declareOutputFields(OutputFieldsDeclarer declarer) {
                // To declare output fields.Not required in this alert.
            }
    
            @Override
            public Map getComponentConfiguration() {
                return null;
            }
    
        }
    

提交回复
热议问题