diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/notice/ApiNoticeDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/notice/ApiNoticeDTO.java index 0a067988cc..b401ea4e55 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/notice/ApiNoticeDTO.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/notice/ApiNoticeDTO.java @@ -22,4 +22,5 @@ public class ApiNoticeDTO implements java.io.Serializable { private String projectId; private List environmentIds; private String reportId; + private String queueId; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequest.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequest.java index 9203f23e2d..7a999aaf03 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequest.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/task/TaskRequest.java @@ -21,6 +21,7 @@ public class TaskRequest implements Serializable { private String kafkaConfig; private String minioConfig; private String poolId; + private String queueId; /** * 是否需要实时接收单个步骤的结果 */ diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java b/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java index 15fdf02e1b..aad8d6628a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/listener/MessageListener.java @@ -1,9 +1,12 @@ package io.metersphere.api.listener; +import io.metersphere.api.event.ApiEventSource; import io.metersphere.api.service.ApiReportSendNoticeService; +import io.metersphere.api.service.queue.ApiExecutionQueueService; +import io.metersphere.sdk.constants.ApplicationScope; import io.metersphere.sdk.constants.KafkaTopicConstants; import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO; -import io.metersphere.sdk.util.CommonBeanFactory; +import io.metersphere.sdk.dto.queue.ExecutionQueueDetail; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.LogUtils; import jakarta.annotation.Resource; @@ -18,17 +21,28 @@ public class MessageListener { @Resource private ApiReportSendNoticeService apiReportSendNoticeService; + @Resource + private ApiEventSource apiEventSource; + + @Resource + private ApiExecutionQueueService apiExecutionQueueService; + @KafkaListener(id = MESSAGE_CONSUME_ID, topics = KafkaTopicConstants.API_REPORT_TASK_TOPIC, groupId = MESSAGE_CONSUME_ID) public void messageConsume(ConsumerRecord record) { try { - if (apiReportSendNoticeService == null) { - apiReportSendNoticeService = CommonBeanFactory.getBean(ApiReportSendNoticeService.class); - } - LogUtils.info("接收到发送通知信息:", record.key()); if (ObjectUtils.isNotEmpty(record.value())) { ApiNoticeDTO dto = JSON.parseObject(record.value(), ApiNoticeDTO.class); apiReportSendNoticeService.sendNotice(dto); + + // TODO 通知测试计划处理后续 + LogUtils.info("发送通知给测试计划:", record.key()); + apiEventSource.fireEvent(ApplicationScope.API_TEST, record.value()); + + // TODO 串行触发下次执行 + ExecutionQueueDetail detail = apiExecutionQueueService.getNextDetail(dto.getQueueId()); + // TODO 调用执行方法 + } } catch (Exception e) { LogUtils.error("接收到发送通知信息:", e); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/listener/MessageListenerTest.java b/backend/services/api-test/src/test/java/io/metersphere/api/listener/MessageListenerTest.java index c0dba4983b..18c7c9c7fd 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/listener/MessageListenerTest.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/listener/MessageListenerTest.java @@ -4,11 +4,11 @@ import io.metersphere.sdk.constants.ApiExecuteResourceType; import io.metersphere.sdk.constants.KafkaTopicConstants; import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO; import io.metersphere.sdk.util.JSON; +import jakarta.annotation.Resource; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; -import org.mockito.InjectMocks; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -19,7 +19,7 @@ import java.util.ArrayList; @AutoConfigureMockMvc public class MessageListenerTest { - @InjectMocks + @Resource private MessageListener messageListener; @Test