设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Kafka之消费与激情(5)

发布时间:2021-05-29 18:39 所属栏目:118 来源:互联网
导读:if(fetcher.sendFetches()0||client.hasPendingRequests()){ client.pollNoWakeup();}returnthis.interceptors.onConsume(newConsumerRecords(records)); }finallongfetchEnd=time.milliseconds();elapsedTime+=fet

                    if (fetcher.sendFetches() > 0 || client.hasPendingRequests()) {  

                        client.pollNoWakeup();                    }                    return this.interceptors.onConsume(new ConsumerRecords<>(records));  

                }                final long fetchEnd = time.milliseconds();                elapsedTime += fetchEnd - metadataEnd;            } while (elapsedTime < timeoutMs);  

            return ConsumerRecords.empty();  

        } finally {  

            release();        }    }  

上述代码中有个方法pollForFetches,它的实现逻辑如下:

private Map<TopicPartition, List<ConsumerRecord<K, V>>> pollForFetches(final long timeoutMs) {  

        final long startMs = time.milliseconds();  

        long pollTimeout = Math.min(coordinator.timeToNextPoll(startMs), timeoutMs);  

        // if data is available already, return it immediately  

        final Map<TopicPartition, List<ConsumerRecord<K, V>>> records = fetcher.fetchedRecords();  

        if (!records.isEmpty()) {  

            return records;  

        }  

        // send any new fetches (won't resend pending fetches)  

        fetcher.sendFetches();  

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读