1. flink sink 不再做batch(pipeline 原本就会多维度写入)

2. RedisUtils 增加hGetAll 和lRange方法
3. 接口调试
pull/6/head
3y 3 years ago
parent ba14aee461
commit 91c1e21078

@ -2,6 +2,7 @@ package com.java3y.austin.cron.xxl.enums;
/**
*
*
* @author 3y
*/
public enum ScheduleTypeEnum {

@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
/**
*
*
* @author 3y
*/
@Data

@ -22,20 +22,8 @@ import java.util.List;
@Slf4j
public class AustinSink implements SinkFunction<AnchorInfo> {
/**
* batch
*/
private static final Integer BATCH_SIZE = 10;
private static final Long TIME_OUT = 2000L;
/**
* ThreadLocal
*/
private static ThreadLocal<List<AnchorInfo>> baseAnchors = ThreadLocal.withInitial(() -> new ArrayList<>(BATCH_SIZE));
private static ThreadLocal<Long> lastClearTime = ThreadLocal.withInitial(() -> new Long(System.currentTimeMillis()));
@Override
public void invoke(AnchorInfo anchorInfo) throws Exception {
public void invoke(AnchorInfo anchorInfo, Context context) throws Exception {
realTimeData(anchorInfo);
offlineDate(anchorInfo);
}
@ -46,16 +34,12 @@ public class AustinSink implements SinkFunction<AnchorInfo> {
* 1.()
* 2.()30
*
* @param anchorInfo
* @param info
*/
private void realTimeData(AnchorInfo anchorInfo) {
baseAnchors.get().add(anchorInfo);
if (baseAnchors.get().size() >= BATCH_SIZE || System.currentTimeMillis() - lastClearTime.get() >= TIME_OUT) {
private void realTimeData(AnchorInfo info) {
try {
LettuceRedisUtils.pipeline(redisAsyncCommands -> {
List<RedisFuture<?>> redisFutures = new ArrayList<>();
for (AnchorInfo info : baseAnchors.get()) {
/**
* 1.userId list:{key,list}
* key:userId,listValue:[{timestamp,state,businessId},{timestamp,state,businessId}]
@ -73,16 +57,11 @@ public class AustinSink implements SinkFunction<AnchorInfo> {
redisFutures.add(redisAsyncCommands.hincrby(String.valueOf(info.getBusinessId()).getBytes(),
String.valueOf(info.getState()).getBytes(), info.getIds().size()));
redisFutures.add(redisAsyncCommands.expire(String.valueOf(info.getBusinessId()).getBytes(), DateUtil.offsetDay(new Date(), 30).getTime()));
}
return redisFutures;
});
} catch (Exception e) {
log.error("AustinSink#invoke error: {}", Throwables.getStackTraceAsString(e));
} finally {
lastClearTime.set(System.currentTimeMillis());
baseAnchors.get().clear();
}
}
}

@ -39,11 +39,40 @@ public class RedisUtils {
}
}
} catch (Exception e) {
log.error("redis mGet fail! e:{}", Throwables.getStackTraceAsString(e));
log.error("RedisUtils#mGet fail! e:{}", Throwables.getStackTraceAsString(e));
}
return result;
}
/**
* hGetAll
*
* @param key
*/
public Map<Object, Object> hGetAll(String key) {
try {
Map<Object, Object> entries = redisTemplate.opsForHash().entries(key);
return entries;
} catch (Exception e) {
log.error("RedisUtils#hGetAll fail! e:{}", Throwables.getStackTraceAsString(e));
}
return null;
}
/**
* lRange
*
* @param key
*/
public List<String> lRange(String key, long start, long end) {
try {
return redisTemplate.opsForList().range(key, start, end);
} catch (Exception e) {
log.error("RedisUtils#lRange fail! e:{}", Throwables.getStackTraceAsString(e));
}
return null;
}
/**
* pipeline key-value
*/
@ -57,7 +86,7 @@ public class RedisUtils {
return null;
});
} catch (Exception e) {
log.error("redis pipelineSetEX fail! e:{}", Throwables.getStackTraceAsString(e));
log.error("RedisUtils#pipelineSetEx fail! e:{}", Throwables.getStackTraceAsString(e));
}
}
@ -67,7 +96,7 @@ public class RedisUtils {
* @param seconds
* @param delta
*/
public void pipelineHashIncrByEX(Map<String, String> keyValues, Long seconds, Long delta) {
public void pipelineHashIncrByEx(Map<String, String> keyValues, Long seconds, Long delta) {
try {
redisTemplate.executePipelined((RedisCallback<String>) connection -> {
for (Map.Entry<String, String> entry : keyValues.entrySet()) {

@ -1,12 +1,17 @@
package com.java3y.austin.web.controller;
import com.alibaba.fastjson.JSON;
import com.java3y.austin.common.vo.BasicResultVO;
import com.java3y.austin.support.domain.MessageTemplate;
import com.java3y.austin.support.utils.RedisUtils;
import com.java3y.austin.web.vo.DataParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* )
*
@ -14,20 +19,22 @@ import org.springframework.web.bind.annotation.*;
*/
@Slf4j
@RestController
@RequestMapping("/messageTemplate")
@RequestMapping("/trace")
@Api("获取数据接口(全链路追踪)")
@CrossOrigin(origins = "http://localhost:3000", allowCredentials = "true", allowedHeaders = "*")
public class DataController {
/**
* Id
* Id
*/
@Autowired
private RedisUtils redisUtils;
@PostMapping("/data")
@ApiOperation("/获取数据")
public BasicResultVO getData(@RequestBody MessageTemplate messageTemplate) {
public BasicResultVO getData(@RequestBody DataParam dataParam) {
Long businessId = dataParam.getBusinessId();
Map<Object, Object> objectObjectMap = redisUtils.hGetAll(String.valueOf(businessId));
log.info("data:{}", JSON.toJSONString(objectObjectMap));
return BasicResultVO.success();
}

@ -0,0 +1,10 @@
package com.java3y.austin.web.service;
/**
*
* @author 3y
*/
public interface DataService {
}
Loading…
Cancel
Save