美文网首页
ProducerInterceptors.java

ProducerInterceptors.java

作者: 上海马超23 | 来源:发表于2018-11-14 21:47 被阅读0次
    public class ProducerInterceptors<K, V> implements Closeable {
        // 拦截器集合
        private final List<ProducerInterceptor<K, V>> interceptors;
    
        // 发送消息时被调用
        public ProducerRecord<K, V> onSend(ProducerRecord<K, V> record) {
            ProducerRecord<K, V> interceptRecord = record;
            for (ProducerInterceptor<K, V> interceptor : this.interceptors) {
                // 循环调用每个拦截器的onSend方法
                interceptRecord = interceptor.onSend(interceptRecord);
            }
            return interceptRecord;
        }
    
        // 收到ACK时被调用
        public void onAcknowledgement(RecordMetadata metadata, Exception exception) {
            for (ProducerInterceptor<K, V> interceptor : this.interceptors) {
                interceptor.onAcknowledgement(metadata, exception);
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:ProducerInterceptors.java

          本文链接:https://www.haomeiwen.com/subject/kiusfqtx.html