justinwwhuang commented on code in PR #10727:
URL: https://github.com/apache/inlong/pull/10727#discussion_r1696164512
##########
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/sources/MqttSource.java:
##########
@@ -54,60 +50,76 @@ private List<Reader> splitSqlJob(String topics, String
instanceId) {
if (StringUtils.isEmpty(topics)) {
return null;
}
- final List<Reader> result = new ArrayList<>();
+ final List<Reader> readers = new ArrayList<>();
String[] topicList = topics.split(CommonConstants.COMMA);
- if (Objects.nonNull(topicList)) {
- Arrays.stream(topicList).forEach(topic -> {
- MqttReader mqttReader = new MqttReader(topic);
- mqttReader.setReadSource(instanceId);
- result.add(mqttReader);
- });
- }
- return result;
+ Arrays.stream(topicList).forEach(topic -> {
+ MqttReader mqttReader = new MqttReader(topic);
+ mqttReader.setReadSource(instanceId);
+ readers.add(mqttReader);
+ });
+ return readers;
}
@Override
public List<Reader> split(TaskProfile conf) {
- String topics = conf.get(JOB_MQTTJOB_TOPICS, StringUtils.EMPTY);
- List<Reader> readerList = null;
- if (StringUtils.isNotEmpty(topics)) {
- }
- if (CollectionUtils.isNotEmpty(readerList)) {
- sourceMetric.sourceSuccessCount.incrementAndGet();
- } else {
- sourceMetric.sourceFailCount.incrementAndGet();
- }
- return readerList;
+ LOGGER.info("start to split mqtt source, conf:{}", conf);
+ String topics = conf.get(TaskConstants.TASK_MQTT_TOPIC,
StringUtils.EMPTY);
+ return splitSqlJob(topics, instanceId);
}
@Override
protected String getThreadName() {
- return null;
+ return "mqtt-source-" + taskId + "-" + instanceId;
}
@Override
protected void initSource(InstanceProfile profile) {
-
+ try {
+ LOGGER.info("MqttSource init: {}", profile.toJsonStr());
+ topic = profile.get(TaskConstants.TASK_MQTT_TOPIC);
+ mqttReader = new MqttReader(topic);
+ mqttReader.init(profile);
+ } catch (Exception e) {
+ stopRunning();
Review Comment:
Suggest that the exception handling here be consistent with other sources
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]