feat:取消完成通过配置决定是否使用mq或者feign
This commit is contained in:
@@ -49,6 +49,13 @@
|
||||
<artifactId>nl-spring-boot-starter-execute</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test 测试相关 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.code.nl.module.task.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 任务业务回调方式
|
||||
*/
|
||||
@Getter
|
||||
public enum TaskCallbackTypeEnum {
|
||||
|
||||
MQ("mq"),
|
||||
|
||||
FEIGN("feign");
|
||||
|
||||
private final String code;
|
||||
|
||||
TaskCallbackTypeEnum(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编码获取任务业务回调方式
|
||||
*
|
||||
* @param code 回调方式编码
|
||||
* @return 任务业务回调方式
|
||||
*/
|
||||
public static TaskCallbackTypeEnum getByCode(String code) {
|
||||
for (TaskCallbackTypeEnum value : values()) {
|
||||
if (value.getCode().equals(code)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package cn.code.nl.module.task.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 任务业务归属服务枚举
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum TaskOwnerServiceEnum {
|
||||
|
||||
LMS("lms", "lms-server"),
|
||||
WMS("wms", "wms-server");
|
||||
|
||||
/**
|
||||
* MQ Topic 前缀
|
||||
*/
|
||||
private final String topicPrefix;
|
||||
|
||||
/**
|
||||
* 服务注册名称
|
||||
*/
|
||||
private final String serviceName;
|
||||
|
||||
/**
|
||||
* 根据业务归属编码获取枚举
|
||||
*
|
||||
* @param code 业务归属编码
|
||||
* @return 业务归属服务枚举
|
||||
*/
|
||||
public static TaskOwnerServiceEnum getByCode(String code) {
|
||||
for (TaskOwnerServiceEnum value : values()) {
|
||||
if (value.name().equalsIgnoreCase(code) || value.serviceName.equalsIgnoreCase(code)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建业务服务消费的 Topic
|
||||
*
|
||||
* @param topic 基础 Topic
|
||||
* @return 完整 Topic
|
||||
*/
|
||||
public String buildTopic(String topic) {
|
||||
return topicPrefix + "_" + topic;
|
||||
}
|
||||
}
|
||||
@@ -44,4 +44,15 @@ public class TaskEventMessage {
|
||||
|
||||
/** 扩展数据 */
|
||||
private Map<String, Object> payload;
|
||||
|
||||
/**
|
||||
* 构建任务事件唯一标识
|
||||
*
|
||||
* @param taskId 任务标识
|
||||
* @param eventType 事件类型
|
||||
* @return 任务事件唯一标识
|
||||
*/
|
||||
public static String buildEventId(Long taskId, String eventType) {
|
||||
return taskId + "_" + eventType;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package cn.code.nl.module.task.enums;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 任务业务归属服务本地 Spring 集成测试
|
||||
*/
|
||||
@SpringBootTest(classes = TaskOwnerServiceEnumLocalSpringTest.TestConfiguration.class)
|
||||
class TaskOwnerServiceEnumLocalSpringTest {
|
||||
|
||||
/**
|
||||
* 验证 LMS 业务归属编码生成消费者 Topic
|
||||
*/
|
||||
@Test
|
||||
void buildTopicShouldSupportLmsOwnerService() {
|
||||
TaskOwnerServiceEnum ownerService = TaskOwnerServiceEnum.getByCode("LMS");
|
||||
|
||||
Assertions.assertNotNull(ownerService);
|
||||
Assertions.assertEquals("lms_task_status_change_dev_topic",
|
||||
ownerService.buildTopic("task_status_change_dev_topic"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证 WMS 业务归属编码生成消费者 Topic
|
||||
*/
|
||||
@Test
|
||||
void buildTopicShouldSupportWmsOwnerService() {
|
||||
TaskOwnerServiceEnum ownerService = TaskOwnerServiceEnum.getByCode("WMS");
|
||||
|
||||
Assertions.assertNotNull(ownerService);
|
||||
Assertions.assertEquals("wms_task_status_change_dev_topic",
|
||||
ownerService.buildTopic("task_status_change_dev_topic"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证兼容服务注册名称并拒绝非法业务归属
|
||||
*/
|
||||
@Test
|
||||
void getByCodeShouldSupportServiceNameAndRejectInvalidCode() {
|
||||
Assertions.assertEquals(TaskOwnerServiceEnum.LMS,
|
||||
TaskOwnerServiceEnum.getByCode("lms-server"));
|
||||
Assertions.assertEquals(TaskOwnerServiceEnum.WMS,
|
||||
TaskOwnerServiceEnum.getByCode("wms-server"));
|
||||
Assertions.assertNull(TaskOwnerServiceEnum.getByCode("invalid-server"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试 Spring 配置
|
||||
*/
|
||||
@Configuration
|
||||
static class TestConfiguration {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user