parent
4871a8f42a
commit
d2e4914f89
@ -0,0 +1,27 @@
|
||||
package com.java3y.austin.stream.constants;
|
||||
|
||||
public class AustinFlinkConstant {
|
||||
|
||||
/**
|
||||
* Kafka 配置信息
|
||||
* TODO 使用前需要把broker配置
|
||||
*/
|
||||
public static final String GROUP_ID = "austinLogGroup";
|
||||
public static final String TOPIC_NAME = "austinLog";
|
||||
public static final String BROKER = "ip:port";
|
||||
|
||||
|
||||
/**
|
||||
* spring配置文件路径
|
||||
*/
|
||||
public static final String SPRING_CONFIG_PATH = "classpath*:austin-spring.xml";
|
||||
|
||||
|
||||
/**
|
||||
* Flink流程常量
|
||||
*/
|
||||
public static final String SOURCE_NAME = "austin_kafka_source";
|
||||
public static final String FUNCTION_NAME = "austin_transfer";
|
||||
public static final String SINK_NAME = "austin_sink";
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.java3y.austin.stream.source;
|
||||
|
||||
import com.java3y.austin.common.domain.AnchorInfo;
|
||||
import org.apache.flink.streaming.api.functions.source.RichSourceFunction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据源 mock
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
public class AustinSource extends RichSourceFunction<AnchorInfo> {
|
||||
@Override
|
||||
public void run(SourceContext<AnchorInfo> sourceContext) throws Exception {
|
||||
List<AnchorInfo> anchorInfoList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
anchorInfoList.add(AnchorInfo.builder()
|
||||
.state(10).businessId(333L)
|
||||
.timestamp(System.currentTimeMillis()).build());
|
||||
|
||||
}
|
||||
for (AnchorInfo anchorInfo : anchorInfoList) {
|
||||
sourceContext.collect(anchorInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.java3y.austin.support.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author 3y
|
||||
* @date 2022/2/16
|
||||
* Kafka工具类
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class KafkaUtils {
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
|
||||
/**
|
||||
* 发送kafka消息
|
||||
*
|
||||
* @param topicName
|
||||
* @param jsonMessage
|
||||
*/
|
||||
public void send(String topicName, String jsonMessage) {
|
||||
kafkaTemplate.send(topicName, jsonMessage);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue