commit
3191d1bd1a
|
@ -1,11 +1,8 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.rule;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBridgePageReqVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBridgeRespVO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.IotDataBridgeSaveReqVO;
|
||||
|
@ -15,16 +12,11 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@Tag(name = "管理后台 - IoT 数据桥梁")
|
||||
|
@ -77,18 +69,4 @@ public class IotDataBridgeController {
|
|||
return success(BeanUtils.toBean(pageResult, IotDataBridgeRespVO.class));
|
||||
}
|
||||
|
||||
// TODO @puhui999:不用导出哈。相关的 IotDataBridgeRespVO 里的导出也注释掉哈
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出数据桥梁 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('iot:data-bridge:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportDataBridgeExcel(@Valid IotDataBridgePageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<IotDataBridgeDO> list = dataBridgeService.getDataBridgePage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "IoT 数据桥梁.xls", "数据", IotDataBridgeRespVO.class,
|
||||
BeanUtils.toBean(list, IotDataBridgeRespVO.class));
|
||||
}
|
||||
|
||||
}
|
|
@ -20,22 +20,11 @@ public class IotDataBridgePageReqVO extends PageParam {
|
|||
@Schema(description = "桥梁名称", example = "赵六")
|
||||
private String name;
|
||||
|
||||
// TODO @puhui999:description、direction、type 不过滤哈
|
||||
@Schema(description = "桥梁描述", example = "随便")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "桥梁状态", example = "2")
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "桥梁方向")
|
||||
private Integer direction;
|
||||
|
||||
@Schema(description = "桥梁类型", example = "1")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
|
||||
}
|
|
@ -1,57 +1,39 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.module.iot.enums.DictTypeConstants.IOT_DATA_BRIDGE_DIRECTION_ENUM;
|
||||
import static cn.iocoder.yudao.module.iot.enums.DictTypeConstants.IOT_DATA_BRIDGE_TYPE_ENUM;
|
||||
import static cn.iocoder.yudao.module.system.enums.DictTypeConstants.COMMON_STATUS;
|
||||
|
||||
@Schema(description = "管理后台 - IoT 数据桥梁 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class IotDataBridgeRespVO {
|
||||
|
||||
@Schema(description = "桥梁编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18564")
|
||||
@ExcelProperty("桥梁编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "桥梁名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
@ExcelProperty("桥梁名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "桥梁描述", example = "随便")
|
||||
@ExcelProperty("桥梁描述")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "桥梁状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty(value = "桥梁状态", converter = DictConvert.class)
|
||||
@DictFormat(COMMON_STATUS)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "桥梁方向", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty(value = "桥梁方向", converter = DictConvert.class)
|
||||
@DictFormat(IOT_DATA_BRIDGE_DIRECTION_ENUM)
|
||||
private Integer direction;
|
||||
|
||||
@Schema(description = "桥梁类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty(value = "桥梁类型", converter = DictConvert.class)
|
||||
@DictFormat(IOT_DATA_BRIDGE_TYPE_ENUM)
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "桥梁配置")
|
||||
@ExcelProperty("桥梁配置")
|
||||
private IotDataBridgeAbstractConfig config;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
|
@ -1,6 +1,10 @@
|
|||
package cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeDirectionEnum;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
@ -22,15 +26,17 @@ public class IotDataBridgeSaveReqVO {
|
|||
|
||||
@Schema(description = "桥梁状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "桥梁状态不能为空")
|
||||
@InEnum(CommonStatusEnum.class)
|
||||
private Integer status;
|
||||
|
||||
// TODO @puhui999:枚举的校验
|
||||
@Schema(description = "桥梁方向", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "桥梁方向不能为空")
|
||||
@InEnum(IotDataBridgeDirectionEnum.class)
|
||||
private Integer direction;
|
||||
|
||||
@Schema(description = "桥梁类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "桥梁类型不能为空")
|
||||
@InEnum(IotDataBridgeTypeEnum.class)
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "桥梁配置")
|
||||
|
|
|
@ -15,12 +15,12 @@ import lombok.Data;
|
|||
@Data
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible = true)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = IotDataBridgeHttpConfig.class, name = "HTTP"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeKafkaMQConfig.class, name = "KAFKA"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeMqttConfig.class, name = "MQTT"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeRabbitMQConfig.class, name = "RABBITMQ"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeRedisStreamMQConfig.class, name = "REDIS_STREAM"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeRocketMQConfig.class, name = "ROCKETMQ"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeHttpConfig.class, name = "1"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeMqttConfig.class, name = "10"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeRedisStreamMQConfig.class, name = "21"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeRocketMQConfig.class, name = "30"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeRabbitMQConfig.class, name = "31"),
|
||||
@JsonSubTypes.Type(value = IotDataBridgeKafkaMQConfig.class, name = "32"),
|
||||
})
|
||||
public abstract class IotDataBridgeAbstractConfig {
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.dal.dataobject.rule;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeDirectionEnum;
|
||||
|
@ -42,7 +43,7 @@ public class IotDataBridgeDO extends BaseDO {
|
|||
/**
|
||||
* 桥梁状态
|
||||
*
|
||||
* 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
|
||||
* 枚举 {@link CommonStatusEnum}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
|
|
|
@ -18,10 +18,7 @@ public interface IotDataBridgeMapper extends BaseMapperX<IotDataBridgeDO> {
|
|||
default PageResult<IotDataBridgeDO> selectPage(IotDataBridgePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<IotDataBridgeDO>()
|
||||
.likeIfPresent(IotDataBridgeDO::getName, reqVO.getName())
|
||||
.likeIfPresent(IotDataBridgeDO::getDescription, reqVO.getDescription())
|
||||
.eqIfPresent(IotDataBridgeDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(IotDataBridgeDO::getDirection, reqVO.getDirection())
|
||||
.eqIfPresent(IotDataBridgeDO::getType, reqVO.getType())
|
||||
.betweenIfPresent(IotDataBridgeDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(IotDataBridgeDO::getId));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeAbstractConfig;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
|
||||
import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeKafkaMQConfig;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -13,7 +12,6 @@ import org.springframework.kafka.core.KafkaTemplate;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -77,38 +75,4 @@ public class IotKafkaMQDataBridgeExecute extends
|
|||
producer.destroy();
|
||||
}
|
||||
|
||||
// TODO @芋艿:测试代码,后续清理
|
||||
public static void main(String[] args) {
|
||||
// 1. 创建一个共享的实例
|
||||
IotKafkaMQDataBridgeExecute action = new IotKafkaMQDataBridgeExecute();
|
||||
|
||||
// 2. 创建共享的配置
|
||||
IotDataBridgeKafkaMQConfig config = new IotDataBridgeKafkaMQConfig();
|
||||
config.setBootstrapServers("127.0.0.1:9092");
|
||||
config.setTopic("test-topic");
|
||||
config.setSsl(false);
|
||||
config.setUsername(null);
|
||||
config.setPassword(null);
|
||||
|
||||
// 3. 创建共享的消息
|
||||
IotDeviceMessage message = IotDeviceMessage.builder()
|
||||
.requestId("TEST-001")
|
||||
.productKey("testProduct")
|
||||
.deviceName("testDevice")
|
||||
.deviceKey("testDeviceKey")
|
||||
.type("property")
|
||||
.identifier("temperature")
|
||||
.data("{\"value\": 60}")
|
||||
.reportTime(LocalDateTime.now())
|
||||
.tenantId(1L)
|
||||
.build();
|
||||
|
||||
// 4. 执行两次测试,验证缓存
|
||||
log.info("[main][第一次执行,应该会创建新的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
|
||||
log.info("[main][第二次执行,应该会复用缓存的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeRabbitMQConfig;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
|
||||
import com.rabbitmq.client.Channel;
|
||||
|
@ -12,7 +11,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* RabbitMQ 的 {@link IotDataBridgeExecute} 实现类
|
||||
|
@ -76,42 +74,4 @@ public class IotRabbitMQDataBridgeExecute extends
|
|||
}
|
||||
}
|
||||
|
||||
// TODO @芋艿:测试代码,后续清理
|
||||
public static void main(String[] args) {
|
||||
// 1. 创建一个共享的实例
|
||||
IotRabbitMQDataBridgeExecute action = new IotRabbitMQDataBridgeExecute();
|
||||
|
||||
// 2. 创建共享的配置
|
||||
IotDataBridgeRabbitMQConfig config = new IotDataBridgeRabbitMQConfig();
|
||||
config.setHost("localhost");
|
||||
config.setPort(5672);
|
||||
config.setVirtualHost("/");
|
||||
config.setUsername("admin");
|
||||
config.setPassword("123456");
|
||||
config.setExchange("test-exchange");
|
||||
config.setRoutingKey("test-key");
|
||||
config.setQueue("test-queue");
|
||||
|
||||
// 3. 创建共享的消息
|
||||
IotDeviceMessage message = IotDeviceMessage.builder()
|
||||
.requestId("TEST-001")
|
||||
.productKey("testProduct")
|
||||
.deviceName("testDevice")
|
||||
.deviceKey("testDeviceKey")
|
||||
.type("property")
|
||||
.identifier("temperature")
|
||||
.data("{\"value\": 60}")
|
||||
.reportTime(LocalDateTime.now())
|
||||
.tenantId(1L)
|
||||
.build();
|
||||
|
||||
// 4. 执行两次测试,验证缓存
|
||||
// 4. 执行两次测试,验证缓存
|
||||
log.info("[main][第一次执行,应该会创建新的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
|
||||
log.info("[main][第二次执行,应该会复用缓存的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
|
|||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeRedisStreamMQConfig;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
@ -21,8 +20,6 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* Redis Stream MQ 的 {@link IotDataBridgeExecute} 实现类
|
||||
*
|
||||
|
@ -96,38 +93,4 @@ public class IotRedisStreamMQDataBridgeExecute extends
|
|||
return json;
|
||||
}
|
||||
|
||||
// TODO @芋艿:测试代码,后续清理
|
||||
public static void main(String[] args) {
|
||||
// 1. 创建一个共享的实例
|
||||
IotRedisStreamMQDataBridgeExecute action = new IotRedisStreamMQDataBridgeExecute();
|
||||
|
||||
// 2. 创建共享的配置
|
||||
IotDataBridgeRedisStreamMQConfig config = new IotDataBridgeRedisStreamMQConfig();
|
||||
config.setHost("127.0.0.1");
|
||||
config.setPort(6379);
|
||||
config.setDatabase(0);
|
||||
config.setPassword("123456");
|
||||
config.setTopic("test-stream");
|
||||
|
||||
// 3. 创建共享的消息
|
||||
IotDeviceMessage message = IotDeviceMessage.builder()
|
||||
.requestId("TEST-001")
|
||||
.productKey("testProduct")
|
||||
.deviceName("testDevice")
|
||||
.deviceKey("testDeviceKey")
|
||||
.type("property")
|
||||
.identifier("temperature")
|
||||
.data("{\"value\": 60}")
|
||||
.reportTime(LocalDateTime.now())
|
||||
.tenantId(1L)
|
||||
.build();
|
||||
|
||||
// 4. 执行两次测试,验证缓存
|
||||
log.info("[main][第一次执行,应该会创建新的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
|
||||
log.info("[main][第二次执行,应该会复用缓存的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.IotDataBridgeRocketMQConfig;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
|
||||
import cn.iocoder.yudao.module.iot.enums.rule.IotDataBridgeTypeEnum;
|
||||
import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -13,8 +12,6 @@ import org.apache.rocketmq.remoting.common.RemotingHelper;
|
|||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* RocketMQ 的 {@link IotDataBridgeExecute} 实现类
|
||||
*
|
||||
|
@ -65,38 +62,4 @@ public class IotRocketMQDataBridgeExecute extends
|
|||
producer.shutdown();
|
||||
}
|
||||
|
||||
// TODO @芋艿:测试代码,后续清理
|
||||
// TODO @puhui999:搞到测试类里。
|
||||
public static void main(String[] args) {
|
||||
// 1. 创建一个共享的实例
|
||||
IotRocketMQDataBridgeExecute action = new IotRocketMQDataBridgeExecute();
|
||||
|
||||
// 2. 创建共享的配置
|
||||
IotDataBridgeRocketMQConfig config = new IotDataBridgeRocketMQConfig();
|
||||
config.setNameServer("127.0.0.1:9876");
|
||||
config.setGroup("test-group");
|
||||
config.setTopic("test-topic");
|
||||
config.setTags("test-tag");
|
||||
|
||||
// 3. 创建共享的消息
|
||||
IotDeviceMessage message = IotDeviceMessage.builder()
|
||||
.requestId("TEST-001")
|
||||
.productKey("testProduct")
|
||||
.deviceName("testDevice")
|
||||
.deviceKey("testDeviceKey")
|
||||
.type("property")
|
||||
.identifier("temperature")
|
||||
.data("{\"value\": 60}")
|
||||
.reportTime(LocalDateTime.now())
|
||||
.tenantId(1L)
|
||||
.build();
|
||||
|
||||
// 4. 执行两次测试,验证缓存
|
||||
log.info("[main][第一次执行,应该会创建新的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
|
||||
log.info("[main][第二次执行,应该会复用缓存的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
package cn.iocoder.yudao.module.iot.service.rule.action.databridge;
|
||||
|
||||
import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest;
|
||||
import cn.iocoder.yudao.module.iot.controller.admin.rule.vo.databridge.config.*;
|
||||
import cn.iocoder.yudao.module.iot.dal.dataobject.rule.IotDataBridgeDO;
|
||||
import cn.iocoder.yudao.module.iot.mq.message.IotDeviceMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
||||
/**
|
||||
* {@link IotDataBridgeExecute} 实现类的测试
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Disabled // 默认禁用,需要手动启用测试
|
||||
@Slf4j
|
||||
public class IotDataBridgeExecuteTest extends BaseMockitoUnitTest {
|
||||
|
||||
private IotDeviceMessage message;
|
||||
|
||||
@Mock
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@InjectMocks
|
||||
private IotHttpDataBridgeExecute httpDataBridgeExecute;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
// 创建共享的测试消息
|
||||
message = IotDeviceMessage.builder()
|
||||
.requestId("TEST-001")
|
||||
.productKey("testProduct")
|
||||
.deviceName("testDevice")
|
||||
.deviceKey("testDeviceKey")
|
||||
.type("property")
|
||||
.identifier("temperature")
|
||||
.data("{\"value\": 60}")
|
||||
.reportTime(LocalDateTime.now())
|
||||
.tenantId(1L)
|
||||
.build();
|
||||
|
||||
// 配置 RestTemplate mock 返回成功响应
|
||||
Mockito.when(restTemplate.exchange(anyString(), any(HttpMethod.class), any(), any(Class.class)))
|
||||
.thenReturn(new ResponseEntity<>("Success", HttpStatus.OK));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKafkaMQDataBridge() {
|
||||
// 1. 创建执行器实例
|
||||
IotKafkaMQDataBridgeExecute action = new IotKafkaMQDataBridgeExecute();
|
||||
|
||||
// 2. 创建配置
|
||||
IotDataBridgeKafkaMQConfig config = new IotDataBridgeKafkaMQConfig();
|
||||
config.setBootstrapServers("127.0.0.1:9092");
|
||||
config.setTopic("test-topic");
|
||||
config.setSsl(false);
|
||||
config.setUsername(null);
|
||||
config.setPassword(null);
|
||||
|
||||
// 3. 执行两次测试,验证缓存
|
||||
log.info("[testKafkaMQDataBridge][第一次执行,应该会创建新的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
|
||||
log.info("[testKafkaMQDataBridge][第二次执行,应该会复用缓存的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRabbitMQDataBridge() {
|
||||
// 1. 创建执行器实例
|
||||
IotRabbitMQDataBridgeExecute action = new IotRabbitMQDataBridgeExecute();
|
||||
|
||||
// 2. 创建配置
|
||||
IotDataBridgeRabbitMQConfig config = new IotDataBridgeRabbitMQConfig();
|
||||
config.setHost("localhost");
|
||||
config.setPort(5672);
|
||||
config.setVirtualHost("/");
|
||||
config.setUsername("admin");
|
||||
config.setPassword("123456");
|
||||
config.setExchange("test-exchange");
|
||||
config.setRoutingKey("test-key");
|
||||
config.setQueue("test-queue");
|
||||
|
||||
// 3. 执行两次测试,验证缓存
|
||||
log.info("[testRabbitMQDataBridge][第一次执行,应该会创建新的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
|
||||
log.info("[testRabbitMQDataBridge][第二次执行,应该会复用缓存的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRedisStreamMQDataBridge() {
|
||||
// 1. 创建执行器实例
|
||||
IotRedisStreamMQDataBridgeExecute action = new IotRedisStreamMQDataBridgeExecute();
|
||||
|
||||
// 2. 创建配置
|
||||
IotDataBridgeRedisStreamMQConfig config = new IotDataBridgeRedisStreamMQConfig();
|
||||
config.setHost("127.0.0.1");
|
||||
config.setPort(6379);
|
||||
config.setDatabase(0);
|
||||
config.setPassword("123456");
|
||||
config.setTopic("test-stream");
|
||||
|
||||
// 3. 执行两次测试,验证缓存
|
||||
log.info("[testRedisStreamMQDataBridge][第一次执行,应该会创建新的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
|
||||
log.info("[testRedisStreamMQDataBridge][第二次执行,应该会复用缓存的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRocketMQDataBridge() {
|
||||
// 1. 创建执行器实例
|
||||
IotRocketMQDataBridgeExecute action = new IotRocketMQDataBridgeExecute();
|
||||
|
||||
// 2. 创建配置
|
||||
IotDataBridgeRocketMQConfig config = new IotDataBridgeRocketMQConfig();
|
||||
config.setNameServer("127.0.0.1:9876");
|
||||
config.setGroup("test-group");
|
||||
config.setTopic("test-topic");
|
||||
config.setTags("test-tag");
|
||||
|
||||
// 3. 执行两次测试,验证缓存
|
||||
log.info("[testRocketMQDataBridge][第一次执行,应该会创建新的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
|
||||
log.info("[testRocketMQDataBridge][第二次执行,应该会复用缓存的 producer]");
|
||||
action.execute(message, new IotDataBridgeDO().setType(action.getType()).setConfig(config));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHttpDataBridge() throws Exception {
|
||||
// 创建配置
|
||||
IotDataBridgeHttpConfig config = new IotDataBridgeHttpConfig();
|
||||
config.setUrl("https://doc.iocoder.cn/");
|
||||
config.setMethod(HttpMethod.GET.name());
|
||||
|
||||
// 执行测试
|
||||
log.info("[testHttpDataBridge][执行HTTP数据桥接测试]");
|
||||
httpDataBridgeExecute.execute(message, new IotDataBridgeDO().setType(httpDataBridgeExecute.getType()).setConfig(config));
|
||||
}
|
||||
|
||||
}
|
|
@ -115,19 +115,18 @@
|
|||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<!-- IoT 数据桥梁的执行器所需消息队列。如果您只需要使用 rocketmq 那么则注释掉其它消息队列即可 -->
|
||||
<!-- TODO @puhui999:默认不使用哈。可以在 iot biz 那,作为 optional 进行引入 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.rocketmq</groupId>
|
||||
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.rocketmq</groupId>-->
|
||||
<!-- <artifactId>rocketmq-spring-boot-starter</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.kafka</groupId>-->
|
||||
<!-- <artifactId>spring-kafka</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-amqp</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<!-- spring boot 配置所需依赖 -->
|
||||
<dependency>
|
||||
|
|
Loading…
Reference in New Issue