我是靠谱客的博主 刻苦饼干,这篇文章主要介绍Kafka查询避免OOM,现在分享给大家,希望可以做个参考。

(1)consumer#ThreadLocal中 在拦截器中最后关闭Consumer close

        if(CurrentConsumerHolder.getCurrentConsumer()!=null){
            KafkaConsumer<String, String> consumer =             
                    CurrentConsumerHolder.getCurrentConsumer();
            consumer.unsubscribe();
            consumer.close(Duration.ofMillis(0));
        }
        CurrentConsumerHolder.clear();

(2)consumer存放到ThreadLocal查询复用

    public KafkaConsumer<String, String> getQueryConsumer() {
        if (CurrentConsumerHolder.getCurrentConsumer() == null) {
            CurrentConsumerHolder.setCurrentConsumer(
                    new KafkaConsumer<>(this.getKafkaProperties()));
        }
        return CurrentConsumerHolder.getCurrentConsumer();
    }

consumer#poll对象 存放到Redis中增加缓存

提高堆内存

接口限流

最后

以上就是刻苦饼干最近收集整理的关于Kafka查询避免OOM的全部内容,更多相关Kafka查询避免OOM内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(108)

评论列表共有 0 条评论

立即
投稿
返回
顶部