实现背景:
消费Kafka数据写入HBase时,单条处理效率太低。需要批量插入hbase,这里自定义时间窗口countWindowAll 实现100条hbase插入一次Hbase
前面我就不写了 直接上核心代码
/*每10秒一个处理窗口*/
DataStream<List<Put>> putList = filterData.countWindowAll(Constants.windowCount).apply(new AllWindowFunction<String, List<Put>, GlobalWindow>() {
@Override
public void apply(GlobalWindow window, Iterable<String> message, Collector<List<Put>> out) throws Exception {
List<Put> putList=new ArrayList<Put>();
for (String value : message)
{
String rowKey=value.replace("::","_");
Put put = new Put(Bytes.toBytes(rowKey.toString()));
String[] column=value.split("::
该博客探讨了在Flink1.8中提高从Kafka消费数据并批量写入HBase的效率问题。通过使用自定义的时间窗口countWindowAll,实现了每100条数据才进行一次HBase的批量插入,以提升整体性能。文章主要关注核心代码,展示了如何自定义RichSinkFunction,并详细解释了open(), invoke()和close()这三个关键方法的实现。"
113605583,9290553,使用cookie和session进行反反爬实践,"['爬虫技术', '网络协议', '数据提取', '网站登录', '安全爬取']
订阅专栏 解锁全文
1616

被折叠的 条评论
为什么被折叠?



