fix(性能测试): 手动停止测试时发送停止消息到data-streaming

This commit is contained in:
Captain.B 2021-02-09 14:49:49 +08:00
parent cd7dff5fb7
commit 7d6d5bc5d8
1 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,8 @@
package io.metersphere.performance.engine.producer;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.metersphere.commons.utils.LogUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
@ -14,11 +16,17 @@ public class LoadTestProducer {
private String topic;
@Resource
private KafkaTemplate<String, Object> kafkaTemplate;
@Resource
private ObjectMapper objectMapper;
public void sendMessage(String reportId) {
Metric metric = new Metric();
metric.setReportId(reportId);
metric.setThreadName("tearDown Thread Group"); // 发送停止消息
this.kafkaTemplate.send(topic, JSON.toJSONString(metric));
try {
this.kafkaTemplate.send(topic, objectMapper.writeValueAsString(metric));
} catch (JsonProcessingException e) {
LogUtil.error("发送停止消息失败", e);
}
}
}