diff --git a/backend/src/main/java/io/metersphere/performance/engine/producer/LoadTestProducer.java b/backend/src/main/java/io/metersphere/performance/engine/producer/LoadTestProducer.java index fd53f98380..c8a6bf3c62 100644 --- a/backend/src/main/java/io/metersphere/performance/engine/producer/LoadTestProducer.java +++ b/backend/src/main/java/io/metersphere/performance/engine/producer/LoadTestProducer.java @@ -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 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); + } } }