撤回流的处理
撤回流是指流式处理过程中,两表join过程中的数据是一条一条跑过来的,即原本可以join到一起的数据在刚开始可能并没有join上。
- 撤回流的格式:
- 解决方案
- 定时器:使用定时器定时10s(数据最大的时间差值),定时器触发时将状态中的数据发送过来
- 如果重复计算这些数据,如何保持结果正确即可;通过每次度量值修改为
当次度量值 - 上次度量值
即可
异步IO
- 减少等待的时间,充分利用已有的资源
- 使用异步IO时,必须保证从头到尾都是异步的操作;即使用异步的连接器
/**
* 获取到 redis 的异步连接
*
* @return 异步链接对象
*/
public static StatefulRedisConnection<String, String> getRedisAsyncConnection() {
RedisClient redisClient = RedisClient.create("redis://hadoop102:6379/2");
return redisClient.connect();
}
/**
* 关闭 redis 的异步连接
*
* @param redisAsyncConn
*/
public static void closeRedisAsyncConnection(StatefulRedisConnection<String, String> redisAsyncConn) {
if (redisAsyncConn != null) {
redisAsyncConn.close();
}
}
/**
* 获取到 Hbase 的异步连接
*
* @return 得到异步连接对象
*/
public static AsyncConnection getHBaseAsyncConnection() {
Configuration conf = new Configuration();
conf.set("hbase.zookeeper.quorum", "hadoop102");
conf.set("hbase.zookeeper.property.clientPort", "2181");
try {
return ConnectionFactory.createAsyncConnection(conf).get();