转自: https://www.jianshu.com/p/932663e9a226

consumer.subscribe(topicA);
consumer.poll(100);//正常订阅topic和poll消息 Set<TopicPartition> assignments = consumer.assignment();//获取consumer所分配的分区信息
Map<TopicPartition, Long> query = new HashMap<>();//构造offsetsForTimes参数,通过时间戳找到offset
for (TopicPartition topicPartition : assignments) {
System.out.println(topicPartition);
query.put(topicPartition, 1550804131000L);
}
Map<TopicPartition, OffsetAndTimestamp> result = consumer.offsetsForTimes(query);
for (Map.Entry<TopicPartition, OffsetAndTimestamp> entry : result.entrySet()) {
System.out.println(entry);
consumer.seek(entry.getKey(), entry.getValue().offset());//每个topic的partition都seek到执行的offset
}

最新文章

  1. Android基础 : Android ContentProvider
  2. 关于AlertDialog.Builder(Context context)中所应传入的context
  3. hdu 4401 Battery
  4. JAVA CAS原理
  5. tomcat部署
  6. MVC1
  7. BNUOJ-26482 Juice 树形DP
  8. hdu 5625 Clarke and chemistry
  9. OAuth认证的过程
  10. Node.js学习笔记2(安装和配置Node.js)
  11. Tomcat中配置自定义404错误页面
  12. Mysql中如何创建、删除授权用户
  13. vs打开项目出错:未找到导入的项目“C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 5.0.props”的解决办法
  14. 构建具有用户身份认证的 Ionic 应用
  15. Elasticsearch-6.7.0系列(一)9200端口 .tar.gz版本centos7环境--下载安装运行
  16. Docker数据卷Volume实现文件共享、数据迁移备份(三)--技术流ken
  17. spring3-mvc-maven-hello-world-master mvn jetty:run 及 mvn war:war 指令
  18. 如何在Markdown文档中插入空格?
  19. hmac库 密钥相关的哈希运算消息认证码
  20. 位(bit)与字节(byte)

热门文章

  1. C# Winform更换Webbrowse为WebKit
  2. linux的装配与虚拟机的快照
  3. 朝花夕拾《精通CSS》一、HTML &amp; CSS 的基础
  4. ETCD:gRPC代理
  5. 使用vue-cli创建工程的时候提示vue-cli Failed to download repo vuejs-templates/webpack-simple:self signed certificate in certificate chain的解决方法
  6. [Spring cloud 一步步实现广告系统] 10. 使用Ribbon 实现微服务调用
  7. centos7.2安装及管理docker
  8. golang 处理 json 结构体
  9. Selenium(四):CSS选择器(一)
  10. arcgis api 4.x for js 图层拓展篇之mapvLayer(附源码下载)