|
@@ -3,6 +3,8 @@ package flink.zanxiangnet.ad.monitoring;
|
|
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
|
import com.zanxiangnet.module.util.DateUtil;
|
|
|
import flink.zanxiangnet.ad.monitoring.pojo.entity.AdStatOfMinuteDWD;
|
|
|
+import flink.zanxiangnet.ad.monitoring.sink.OssBatchStreamSink;
|
|
|
+import flink.zanxiangnet.ad.monitoring.stream.BatchStream;
|
|
|
import flink.zanxiangnet.ad.monitoring.stream.KeyedBatchStream;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.Builder;
|
|
@@ -16,12 +18,14 @@ import org.apache.flink.streaming.api.datastream.DataStreamSource;
|
|
|
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
|
|
|
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
|
|
|
import org.apache.flink.streaming.api.functions.ProcessFunction;
|
|
|
+import org.apache.flink.streaming.api.functions.sink.SinkFunction;
|
|
|
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
|
|
|
import org.apache.flink.streaming.api.windowing.time.Time;
|
|
|
import org.apache.flink.util.Collector;
|
|
|
|
|
|
import java.time.Duration;
|
|
|
import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -60,14 +64,19 @@ public class Test {
|
|
|
}
|
|
|
}
|
|
|
});*/
|
|
|
- new KeyedBatchStream<>(pojoStream, Pojo::getUserId, 10L, Time.seconds(16))
|
|
|
- .toBatch()
|
|
|
- .process(new ProcessFunction<List<Pojo>, String>() {
|
|
|
+ SingleOutputStreamOperator<Pojo> streamOperator = pojoStream.keyBy(Pojo::getUserId).process(new ProcessFunction<Pojo, Pojo>() {
|
|
|
+ @Override
|
|
|
+ public void processElement(Pojo value, ProcessFunction<Pojo, Pojo>.Context ctx, Collector<Pojo> out) throws Exception {
|
|
|
+ out.collect(value);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ new BatchStream<>(streamOperator, 100L, Time.minutes(1))
|
|
|
+ .toBatch().addSink(new SinkFunction<List<Pojo>>() {
|
|
|
@Override
|
|
|
- public void processElement(List<Pojo> value, ProcessFunction<List<Pojo>, String>.Context ctx, Collector<String> out) throws Exception {
|
|
|
- out.collect("收到 " + value.size() + "个元素!" + value.stream().map(Pojo::getIndex).collect(Collectors.toList()));
|
|
|
+ public void invoke(List<Pojo> value, Context context) throws Exception {
|
|
|
+ log.error("pojo大小:{}, userIds: {}", value.size(), value.stream().map(Pojo::getUserId).collect(Collectors.toSet()));
|
|
|
}
|
|
|
- }).print();
|
|
|
+ });
|
|
|
/*pojoStream.keyBy(Pojo::getUserId)
|
|
|
.window(TumblingEventTimeWindows.of(Time.days(1L), Time.hours(-8)))
|
|
|
.trigger(new Trigger<Pojo, TimeWindow>() {
|
|
@@ -252,12 +261,13 @@ public class Test {
|
|
|
|
|
|
@Override
|
|
|
public void run(SourceContext<Pojo> sourceContext) {
|
|
|
+ Random random = new Random();
|
|
|
while (isRun) {
|
|
|
try {
|
|
|
for (int i = 0; i < 24; i++) {
|
|
|
long user1Index = index1.incrementAndGet();
|
|
|
Pojo pojo = Pojo.builder()
|
|
|
- .userId(1)
|
|
|
+ .userId(random.nextInt(100))
|
|
|
.index(user1Index)
|
|
|
.createTime(BEGIN + ((user1Index - 1) * 60 * 60 * 1000))
|
|
|
.build();
|