Merge branch 'feature'

V0.5.x
xiwa 2022-08-18 20:04:20 +08:00
commit db8907956f
85 changed files with 712 additions and 232 deletions

View File

@ -5,7 +5,7 @@
"name": "MQTT标准协议组件", "name": "MQTT标准协议组件",
"type": "device", "type": "device",
"protocol": "mqtt", "protocol": "mqtt",
"jarFile": "iot-mqtt-component-0.4.0-SNAPSHOT.jar", "jarFile": "iot-mqtt-component-0.4.2-SNAPSHOT.jar",
"config": "{\"port\":1883,\"ssl\":false,\"type\":\"server\"}", "config": "{\"port\":1883,\"ssl\":false,\"type\":\"server\"}",
"converter": "6260396d67aced2696184053", "converter": "6260396d67aced2696184053",
"state": "running", "state": "running",
@ -17,7 +17,7 @@
"name": "EMQX标准协议组件", "name": "EMQX标准协议组件",
"type": "device", "type": "device",
"protocol": "mqtt", "protocol": "mqtt",
"jarFile": "iot-emqx-component-0.4.0-SNAPSHOT.jar", "jarFile": "iot-emqx-component-0.4.2-SNAPSHOT.jar",
"config": "{\"port\":\"1884\",\"ssl\":false,\"type\":\"client\",\"subscribeTopics\":[\"/sys/+/+/s/#\",\"/sys/client/connected\",\"/sys/client/disconnected\",\"/sys/session/subscribed\",\"/sys/session/unsubscribed\"],\"authPort\":\"8088\",\"broker\":\"127.0.0.1\",\"clientId\":\"test\",\"username\":\"test\",\"password\":\"123\"}", "config": "{\"port\":\"1884\",\"ssl\":false,\"type\":\"client\",\"subscribeTopics\":[\"/sys/+/+/s/#\",\"/sys/client/connected\",\"/sys/client/disconnected\",\"/sys/session/subscribed\",\"/sys/session/unsubscribed\"],\"authPort\":\"8088\",\"broker\":\"127.0.0.1\",\"clientId\":\"test\",\"username\":\"test\",\"password\":\"123\"}",
"converter": "6260396d67aced2696184053", "converter": "6260396d67aced2696184053",
"state": "stopped", "state": "stopped",
@ -29,7 +29,7 @@
"name": "小度音箱接入组件", "name": "小度音箱接入组件",
"type": "biz", "type": "biz",
"protocol": "http", "protocol": "http",
"jarFile": "iot-http-biz-component-0.4.0-SNAPSHOT.jar", "jarFile": "iot-http-biz-component-0.4.2-SNAPSHOT.jar",
"config": "{\"port\":\"8084\"}", "config": "{\"port\":\"8084\"}",
"converter": "", "converter": "",
"state": "stopped", "state": "stopped",

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-components</artifactId> <artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -12,10 +12,14 @@ package cc.iotkit.comp;
import cc.iotkit.comp.model.ReceiveResult; import cc.iotkit.comp.model.ReceiveResult;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Callable;
import java.util.function.Consumer;
public interface IMessageHandler { public interface IMessageHandler {
ReceiveResult onReceive(Map<String, Object> head, String type, String msg); void onReceive(Map<String, Object> head, String type, String msg);
void onReceive(Map<String, Object> head, String type, String msg, Consumer<ReceiveResult> onResult);
/** /**
* *

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-components</artifactId> <artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-components</artifactId> <artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -84,7 +84,7 @@
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-message-bus</artifactId> <artifactId>iot-message-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -32,6 +32,8 @@ import org.apache.commons.beanutils.BeanUtils;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import javax.script.ScriptException; import javax.script.ScriptException;
import java.util.Map; import java.util.Map;
import java.util.concurrent.*;
import java.util.function.Consumer;
@Slf4j @Slf4j
@Data @Data
@ -50,6 +52,10 @@ public class DeviceMessageHandler implements IMessageHandler {
private final DeviceRouter deviceRouter; private final DeviceRouter deviceRouter;
private final ExecutorService executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>());
@SneakyThrows @SneakyThrows
public DeviceMessageHandler(DeviceComponentManager deviceComponentManager, public DeviceMessageHandler(DeviceComponentManager deviceComponentManager,
IDeviceComponent component, IDeviceComponent component,
@ -67,13 +73,20 @@ public class DeviceMessageHandler implements IMessageHandler {
scriptObj = engine.eval(String.format("new (function () {\n%s})()", script)); scriptObj = engine.eval(String.format("new (function () {\n%s})()", script));
} }
public ReceiveResult onReceive(Map<String, Object> head, String type, String msg) { public void onReceive(Map<String, Object> head, String type, String msg) {
onReceive(head, type, msg, (r) -> {
});
}
public void onReceive(Map<String, Object> head, String type, String msg, Consumer<ReceiveResult> onResult) {
executorService.submit(() -> {
try { try {
ScriptObjectMirror result = (ScriptObjectMirror) invokeMethod("onReceive", head, type, msg); ScriptObjectMirror result = (ScriptObjectMirror) invokeMethod("onReceive", head, type, msg);
log.info("onReceive script result:{}", JsonUtil.toJsonString(result)); log.info("onReceive script result:{}", JsonUtil.toJsonString(result));
Object rstType = result.get("type"); Object rstType = result.get("type");
if (rstType == null) { if (rstType == null) {
return null; onResult.accept(null);
return;
} }
//取脚本执行后返回的数据 //取脚本执行后返回的数据
Object data = JsonUtil.toObject((ScriptObjectMirror) result.get("data")); Object data = JsonUtil.toObject((ScriptObjectMirror) result.get("data"));
@ -89,34 +102,40 @@ public class DeviceMessageHandler implements IMessageHandler {
//注册数据 //注册数据
RegisterInfo regInfo = RegisterInfo.from(dataMap); RegisterInfo regInfo = RegisterInfo.from(dataMap);
if (regInfo == null) { if (regInfo == null) {
return null; onResult.accept(null);
return;
} }
doRegister(regInfo); doRegister(regInfo);
doAction(action); doAction(action);
return new ReceiveResult(regInfo.getProductKey(), regInfo.getDeviceName(), regInfo); onResult.accept(new ReceiveResult(regInfo.getProductKey(), regInfo.getDeviceName(), regInfo));
return;
} else if ("auth".equals(rstType)) { } else if ("auth".equals(rstType)) {
//设备认证 //设备认证
AuthInfo authInfo = new AuthInfo(); AuthInfo authInfo = new AuthInfo();
BeanUtils.populate(authInfo, dataMap); BeanUtils.populate(authInfo, dataMap);
doAuth(authInfo); doAuth(authInfo);
doAction(action); doAction(action);
return new ReceiveResult(authInfo.getProductKey(), authInfo.getDeviceName(), authInfo); onResult.accept(new ReceiveResult(authInfo.getProductKey(), authInfo.getDeviceName(), authInfo));
return;
} else if ("state".equals(rstType)) { } else if ("state".equals(rstType)) {
//设备状态变更 //设备状态变更
DeviceState state = DeviceState.from(dataMap); DeviceState state = DeviceState.from(dataMap);
if (state == null) { if (state == null) {
return null; onResult.accept(null);
return;
} }
doStateChange(state); doStateChange(state);
doAction(action); doAction(action);
return new ReceiveResult(state.getProductKey(), state.getDeviceName(), state); onResult.accept(new ReceiveResult(state.getProductKey(), state.getDeviceName(), state));
return;
} else if ("report".equals(rstType)) { } else if ("report".equals(rstType)) {
//上报数据 //上报数据
DeviceMessage message = new DeviceMessage(); DeviceMessage message = new DeviceMessage();
BeanUtils.populate(message, dataMap); BeanUtils.populate(message, dataMap);
doReport(message); doReport(message);
doAction(action); doAction(action);
return new ReceiveResult(message.getProductKey(), message.getDeviceName(), message); onResult.accept(new ReceiveResult(message.getProductKey(), message.getDeviceName(), message));
return;
} }
} catch (BizException e) { } catch (BizException e) {
@ -124,7 +143,8 @@ public class DeviceMessageHandler implements IMessageHandler {
} catch (Throwable e) { } catch (Throwable e) {
throw new BizException("receive component message error", e); throw new BizException("receive component message error", e);
} }
return null; onResult.accept(null);
});
} }
private void doRegister(RegisterInfo reg) throws ScriptException, NoSuchMethodException { private void doRegister(RegisterInfo reg) throws ScriptException, NoSuchMethodException {

View File

@ -0,0 +1,16 @@
package cc.iotkit.comps;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Map;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MessageInfo {
private Map<String, Object> head;
private String type;
private String msg;
}

View File

@ -1,15 +1,9 @@
package cc.iotkit.comps.config; package cc.iotkit.comps.config;
import cc.iotkit.model.device.message.ThingModelMessage;
import cc.iotkit.mq.MqConsumer;
import cc.iotkit.mq.MqProducer;
import cc.iotkit.mq.vertx.VertxMqConsumer;
import cc.iotkit.mq.vertx.VertxMqProducer;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.Data; import lombok.Data;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -41,16 +35,5 @@ public class ComponentConfig {
return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); return new ObjectMapper().disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
} }
@ConditionalOnMissingBean
@Bean
public MqProducer<ThingModelMessage> getThingModelMessageProducer() {
return new VertxMqProducer<>(ThingModelMessage.class);
}
@ConditionalOnMissingBean
@Bean
public MqConsumer<ThingModelMessage> getThingModelMessageConsumer() {
return new VertxMqConsumer<>(ThingModelMessage.class);
}
} }

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-components</artifactId> <artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -3,7 +3,7 @@
<parent> <parent>
<artifactId>iot-components</artifactId> <artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>iot-emqx-component</artifactId> <artifactId>iot-emqx-component</artifactId>
@ -84,25 +84,25 @@
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-model</artifactId> <artifactId>iot-model</artifactId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-common</artifactId> <artifactId>iot-common</artifactId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-component-base</artifactId> <artifactId>iot-component-base</artifactId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-data-service</artifactId> <artifactId>iot-data-service</artifactId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-components</artifactId> <artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -3,7 +3,7 @@
<parent> <parent>
<artifactId>iot-components</artifactId> <artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>iot-http-biz-component</artifactId> <artifactId>iot-http-biz-component</artifactId>
@ -58,7 +58,7 @@
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-component-base</artifactId> <artifactId>iot-component-base</artifactId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-components</artifactId> <artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -3,7 +3,7 @@
<parent> <parent>
<artifactId>iot-components</artifactId> <artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>iot-mqtt-component</artifactId> <artifactId>iot-mqtt-component</artifactId>
@ -82,19 +82,19 @@
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-common</artifactId> <artifactId>iot-common</artifactId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-component-base</artifactId> <artifactId>iot-component-base</artifactId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-data-service</artifactId> <artifactId>iot-data-service</artifactId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-components</artifactId> <artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -76,9 +76,11 @@ public class MqttVerticle extends AbstractVerticle {
log.info("MQTT client auth,clientId:{},username:{},password:{}", log.info("MQTT client auth,clientId:{},username:{},password:{}",
clientId, auth.getUsername(), auth.getPassword()); clientId, auth.getUsername(), auth.getPassword());
try { try {
ReceiveResult result = executor.onReceive(new HashMap<>(), "auth", authJson); executor.onReceive(new HashMap<>(), "auth", authJson, (r) -> {
//保存设备与连接关系 //保存设备与连接关系
endpointMap.put(getEndpointKey(result), endpoint); endpointMap.put(getEndpointKey(r), endpoint);
});
} catch (Throwable e) { } catch (Throwable e) {
log.error("auth failed", e); log.error("auth failed", e);
endpoint.reject(MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED); endpoint.reject(MqttConnectReturnCode.CONNECTION_REFUSED_NOT_AUTHORIZED);
@ -90,14 +92,16 @@ public class MqttVerticle extends AbstractVerticle {
endpoint.accept(false); endpoint.accept(false);
endpoint.closeHandler((v) -> { endpoint.closeHandler((v) -> {
log.warn("client connection closed,clientId:{}", clientId); log.warn("client connection closed,clientId:{}", clientId);
ReceiveResult result = executor.onReceive(new HashMap<>(), "disconnect", clientId); executor.onReceive(new HashMap<>(), "disconnect", clientId, (r) -> {
//删除设备与连接关系 //删除设备与连接关系
endpointMap.remove(getEndpointKey(result)); endpointMap.remove(getEndpointKey(r));
});
}).disconnectMessageHandler(disconnectMessage -> { }).disconnectMessageHandler(disconnectMessage -> {
log.info("Received disconnect from client, reason code = {}", disconnectMessage.code()); log.info("Received disconnect from client, reason code = {}", disconnectMessage.code());
ReceiveResult result = executor.onReceive(new HashMap<>(), "disconnect", clientId); executor.onReceive(new HashMap<>(), "disconnect", clientId, (r) -> {
//删除设备与连接关系 //删除设备与连接关系
endpointMap.remove(getEndpointKey(result)); endpointMap.remove(getEndpointKey(r));
});
}).subscribeHandler(subscribe -> { }).subscribeHandler(subscribe -> {
List<MqttSubAckReasonCode> reasonCodes = new ArrayList<>(); List<MqttSubAckReasonCode> reasonCodes = new ArrayList<>();
for (MqttTopicSubscription s : subscribe.topicSubscriptions()) { for (MqttTopicSubscription s : subscribe.topicSubscriptions()) {

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-data</artifactId> <artifactId>iot-data</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-data</artifactId> <artifactId>iot-data</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-data</artifactId> <artifactId>iot-data</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.es.document; package cc.iotkit.temporal.es.document;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -12,7 +12,7 @@ public class DbStructureDataImpl implements IDbStructureData {
} }
@Override @Override
public void undefineThingModel(ThingModel thingModel) { public void updateThingModel(ThingModel thingModel) {
} }

View File

@ -5,9 +5,9 @@
<parent> <parent>
<artifactId>iot-data</artifactId> <artifactId>iot-data</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>iot-model</artifactId> <artifactId>iot-model</artifactId>

View File

@ -5,9 +5,9 @@
<parent> <parent>
<artifactId>iot-data</artifactId> <artifactId>iot-data</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>iot-rdb-data-service</artifactId> <artifactId>iot-rdb-data-service</artifactId>

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.data.IUserInfoData; import cc.iotkit.data.IUserInfoData;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.data.service; package cc.iotkit.data.service;
import cc.iotkit.data.IVirtualDeviceData; import cc.iotkit.data.IVirtualDeviceData;

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-data</artifactId> <artifactId>iot-data</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -1,5 +1,7 @@
### 时序数据库服务接口的TDengine实现 ### 时序数据库服务接口的TDengine实现
版本v0.4.1 支持版本v0.4.1
TDengine版本2.6.0.12

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.config; package cc.iotkit.temporal.td.config;
public interface Constants { public interface Constants {

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.config; package cc.iotkit.temporal.td.config;
import cc.iotkit.temporal.td.dao.TdTemplate; import cc.iotkit.temporal.td.dao.TdTemplate;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.dao; package cc.iotkit.temporal.td.dao;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.dm; package cc.iotkit.temporal.td.dm;
import cc.iotkit.model.product.ThingModel; import cc.iotkit.model.product.ThingModel;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.dm; package cc.iotkit.temporal.td.dm;
import java.util.List; import java.util.List;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.dm; package cc.iotkit.temporal.td.dm;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.dm; package cc.iotkit.temporal.td.dm;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.dm; package cc.iotkit.temporal.td.dm;
import cc.iotkit.common.utils.JsonUtil; import cc.iotkit.common.utils.JsonUtil;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.model; package cc.iotkit.temporal.td.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.model; package cc.iotkit.temporal.td.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.model; package cc.iotkit.temporal.td.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.model; package cc.iotkit.temporal.td.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.model; package cc.iotkit.temporal.td.model;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.temporal.td.service; package cc.iotkit.temporal.td.service;
import cc.iotkit.common.utils.JsonUtil; import cc.iotkit.common.utils.JsonUtil;
@ -50,7 +59,8 @@ public class DbStructureDataImpl implements IDbStructureData {
* *
*/ */
@Override @Override
public void undefineThingModel(ThingModel thingModel) { public void updateThingModel(ThingModel thingModel) {
try {
//获取旧字段信息 //获取旧字段信息
String tbName = Constants.getProductPropertySTableName(thingModel.getProductKey()); String tbName = Constants.getProductPropertySTableName(thingModel.getProductKey());
String sql = TableManager.getDescTableSql(tbName); String sql = TableManager.getDescTableSql(tbName);
@ -80,7 +90,7 @@ public class DbStructureDataImpl implements IDbStructureData {
.anyMatch(old -> .anyMatch(old ->
old.getName().equals(f.getName()) //字段名相同 old.getName().equals(f.getName()) //字段名相同
//字段类型或长度不同 //字段类型或长度不同
&& (old.getType().equals(f.getType()) || old.getLength() != f.getLength()) && (!old.getType().equals(f.getType()) || old.getLength() != f.getLength())
)) ))
.collect(Collectors.toList()); .collect(Collectors.toList());
@ -93,8 +103,11 @@ public class DbStructureDataImpl implements IDbStructureData {
} }
//找出删除的字段 //找出删除的字段
List<TdField> dropFields = oldFields.stream().filter((f) -> newFields.stream() List<TdField> dropFields = oldFields.stream().filter((f) ->
.noneMatch(old -> old.getName().equals(f.getName()))) !"time".equals(f.getName()) &&
!"device_id".equals(f.getName()) && newFields.stream()
//字段名不是time且没有相同字段名的
.noneMatch(n -> n.getName().equals(f.getName())))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (dropFields.size() > 0) { if (dropFields.size() > 0) {
sql = TableManager.getDropSTableColumnSql(tbName, dropFields); sql = TableManager.getDropSTableColumnSql(tbName, dropFields);
@ -103,6 +116,9 @@ public class DbStructureDataImpl implements IDbStructureData {
throw new RuntimeException("drop table column error:" + JsonUtil.toJsonString(response)); throw new RuntimeException("drop table column error:" + JsonUtil.toJsonString(response));
} }
} }
} catch (Throwable e) {
log.error("update thingmodel stable failed", e);
}
} }
/** /**

View File

@ -36,32 +36,29 @@ public class ThingModelMessageDataImpl implements IThingModelMessageData {
String identifier, String identifier,
int page, int size) { int page, int size) {
String sql = "select time,mid,product_key,device_name,type,identifier,code,data,report_time " + String sql = "select time,mid,product_key,device_name,type,identifier,code,data,report_time " +
"from thing_model_message_%s %s order by time desc limit %d offset %d"; "from thing_model_message where device_id=? %s order by time desc limit %d offset %d";
//构建动态条件 //构建动态条件
List<Object> args = new ArrayList<>(); List<Object> args = new ArrayList<>();
List<String> cons = new ArrayList<>(); args.add(deviceId);
StringBuilder sbCond = new StringBuilder();
if (StringUtils.isNotBlank(type)) { if (StringUtils.isNotBlank(type)) {
cons.add("type=?"); sbCond.append(" and type=? ");
args.add(type); args.add(type);
} }
if (StringUtils.isNotBlank(identifier)) { if (StringUtils.isNotBlank(identifier)) {
cons.add("identifier=?"); sbCond.append("and identifier=? ");
args.add(identifier); args.add(identifier);
} }
String condition = "";
if (cons.size() > 0) {
condition = "where " + String.join(" and ", cons);
}
sql = String.format(sql, deviceId.toLowerCase(), condition, size, (page - 1) * size); sql = String.format(sql, sbCond.toString(), size, (page - 1) * size);
List<TbThingModelMessage> ruleLogs = tdTemplate.query(sql, List<TbThingModelMessage> ruleLogs = tdTemplate.query(sql,
new BeanPropertyRowMapper<>(TbThingModelMessage.class), new BeanPropertyRowMapper<>(TbThingModelMessage.class),
args.toArray() args.toArray()
); );
sql = String.format("select count(*) from thing_model_message_%s %s", sql = String.format("select count(*) from thing_model_message where device_id=? %s",
deviceId.toLowerCase(), condition); sbCond.toString());
List<Long> counts = tdTemplate.queryForList(sql, Long.class, args.toArray()); List<Long> counts = tdTemplate.queryForList(sql, Long.class, args.toArray());
long count = counts.size() > 0 ? counts.get(0) : 0; long count = counts.size() > 0 ? counts.get(0) : 0;

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-data</artifactId> <artifactId>iot-data</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -13,9 +13,9 @@ public interface IDbStructureData {
void defineThingModel(ThingModel thingModel); void defineThingModel(ThingModel thingModel);
/** /**
* *
*/ */
void undefineThingModel(ThingModel thingModel); void updateThingModel(ThingModel thingModel);
/** /**
* *

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging> <packaging>pom</packaging>
@ -17,6 +17,7 @@
<module>iot-temporal-service</module> <module>iot-temporal-service</module>
<module>iot-es-temporal-service</module> <module>iot-es-temporal-service</module>
<module>iot-rdb-data-service</module> <module>iot-rdb-data-service</module>
<module>iot-td-temporal-service</module>
</modules> </modules>
<artifactId>iot-data</artifactId> <artifactId>iot-data</artifactId>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>iot-message-bus</artifactId>
<groupId>cc.iotkit</groupId>
<version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>iot-message-core</artifactId>
</project>

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>iot-message-bus</artifactId>
<groupId>cc.iotkit</groupId>
<version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>iot-message-rocketmq</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-client</artifactId>
<version>4.9.4</version>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-model</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-message-core</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,11 @@
### 支持rocketMq作为消息总线
版本0.4.2
rocketMq版本4.9.4
####开启方式:
1、application.yml中打开注释支持rocketMq作为消息总线
2、pom.xml中打开注释使用rocketmq消息总线

View File

@ -0,0 +1,47 @@
package cc.iotkit.rocketmq;
import cc.iotkit.common.utils.JsonUtil;
import cc.iotkit.mq.ConsumerHandler;
import cc.iotkit.mq.MqConsumer;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.beans.factory.annotation.Value;
import java.nio.charset.StandardCharsets;
@Slf4j
public class RocketMqConsumer<T> implements MqConsumer<T> {
private String nameServer;
private final Class<T> msgType;
public RocketMqConsumer(String nameServer, Class<T> cls) {
this.nameServer = nameServer;
this.msgType = cls;
}
@Override
public void consume(String topic, ConsumerHandler<T> handler) {
try {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(handler.getClass()
.getName().replace(".", ""));
consumer.setNamesrvAddr(nameServer);
consumer.subscribe(topic, "*");
consumer.registerMessageListener((MessageListenerConcurrently) (messages, context) -> {
for (MessageExt message : messages) {
T msg = JsonUtil.parse(new String(message.getBody(), StandardCharsets.UTF_8), msgType);
handler.handler(msg);
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
});
consumer.start();
} catch (Throwable e) {
log.error("consume error", e);
}
}
}

View File

@ -0,0 +1,35 @@
package cc.iotkit.rocketmq;
import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.utils.JsonUtil;
import cc.iotkit.mq.MqProducer;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import java.nio.charset.StandardCharsets;
public class RocketMqProducer<T> implements MqProducer<T> {
private final DefaultMQProducer producer;
public RocketMqProducer(String nameServer, String group) {
try {
producer = new DefaultMQProducer(group);
producer.setNamesrvAddr(nameServer);
producer.start();
} catch (Throwable e) {
throw new BizException("init producer error", e);
}
}
@Override
public void publish(String topic, T msg) {
try {
producer.send(new Message(topic,
JsonUtil.toJsonString(msg).getBytes(StandardCharsets.UTF_8)));
} catch (Throwable e) {
throw new BizException("publish msg error", e);
}
}
}

View File

@ -0,0 +1,35 @@
package cc.iotkit.rocketmq.config;
import cc.iotkit.model.device.message.ThingModelMessage;
import cc.iotkit.mq.MqConsumer;
import cc.iotkit.mq.MqProducer;
import cc.iotkit.rocketmq.RocketMqConsumer;
import cc.iotkit.rocketmq.RocketMqProducer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RocketMqConfig {
@Value("${rocketmq.name-server}")
private String nameServer;
@Value("${rocketmq.producer.group}")
private String group;
@ConditionalOnMissingBean
@Bean
public MqProducer<ThingModelMessage> getThingModelMessageProducer() {
return new RocketMqProducer<>(nameServer, group);
}
@ConditionalOnMissingBean
@Bean
public MqConsumer<ThingModelMessage> getThingModelMessageConsumer() {
return new RocketMqConsumer<>(nameServer, ThingModelMessage.class);
}
}

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>iot-message-bus</artifactId>
<groupId>cc.iotkit</groupId>
<version>0.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>iot-vertx-event-bus</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-message-core</artifactId>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-model</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,4 +1,13 @@
package cc.iotkit.mq.vertx; /*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.vertx;
import cc.iotkit.common.utils.JsonUtil; import cc.iotkit.common.utils.JsonUtil;
import io.vertx.core.buffer.Buffer; import io.vertx.core.buffer.Buffer;

View File

@ -7,7 +7,7 @@
* | Author: xw2sy@163.com * | Author: xw2sy@163.com
* +---------------------------------------------------------------------- * +----------------------------------------------------------------------
*/ */
package cc.iotkit.mq.vertx; package cc.iotkit.vertx;
import io.vertx.core.Vertx; import io.vertx.core.Vertx;

View File

@ -7,9 +7,8 @@
* | Author: xw2sy@163.com * | Author: xw2sy@163.com
* +---------------------------------------------------------------------- * +----------------------------------------------------------------------
*/ */
package cc.iotkit.mq.vertx; package cc.iotkit.vertx;
import cc.iotkit.common.utils.JsonUtil;
import cc.iotkit.mq.ConsumerHandler; import cc.iotkit.mq.ConsumerHandler;
import cc.iotkit.mq.MqConsumer; import cc.iotkit.mq.MqConsumer;
import io.vertx.core.AbstractVerticle; import io.vertx.core.AbstractVerticle;

View File

@ -1,4 +1,4 @@
package cc.iotkit.mq.vertx; package cc.iotkit.vertx;
import cc.iotkit.mq.MqProducer; import cc.iotkit.mq.MqProducer;
import io.vertx.core.AbstractVerticle; import io.vertx.core.AbstractVerticle;

View File

@ -0,0 +1,27 @@
package cc.iotkit.vertx.config;
import cc.iotkit.model.device.message.ThingModelMessage;
import cc.iotkit.mq.MqConsumer;
import cc.iotkit.mq.MqProducer;
import cc.iotkit.vertx.VertxMqConsumer;
import cc.iotkit.vertx.VertxMqProducer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class VertxConfig {
@ConditionalOnMissingBean
@Bean
public MqProducer<ThingModelMessage> getThingModelMessageProducer() {
return new VertxMqProducer<>(ThingModelMessage.class);
}
@ConditionalOnMissingBean
@Bean
public MqConsumer<ThingModelMessage> getThingModelMessageConsumer() {
return new VertxMqConsumer<>(ThingModelMessage.class);
}
}

View File

@ -1,8 +1,8 @@
package test; package test;
import cc.iotkit.mq.ConsumerHandler; import cc.iotkit.mq.ConsumerHandler;
import cc.iotkit.mq.vertx.VertxMqConsumer; import cc.iotkit.vertx.VertxMqConsumer;
import cc.iotkit.mq.vertx.VertxMqProducer; import cc.iotkit.vertx.VertxMqProducer;
import io.vertx.core.AsyncResult; import io.vertx.core.AsyncResult;
import io.vertx.core.Handler; import io.vertx.core.Handler;
import io.vertx.core.Vertx; import io.vertx.core.Vertx;

View File

@ -5,12 +5,19 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging>
<artifactId>iot-message-bus</artifactId> <artifactId>iot-message-bus</artifactId>
<modules>
<module>iot-message-core</module>
<module>iot-vertx-event-bus</module>
<module>iot-message-rocketmq</module>
</modules>
<dependencies> <dependencies>
<dependency> <dependency>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -68,7 +68,7 @@
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-message-bus</artifactId> <artifactId>iot-message-core</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -11,14 +11,9 @@ package cc.iotkit.ruleengine.config;
import cc.iotkit.model.device.message.ThingModelMessage; import cc.iotkit.model.device.message.ThingModelMessage;
import cc.iotkit.mq.MqConsumer; import cc.iotkit.mq.MqConsumer;
import cc.iotkit.mq.MqProducer;
import cc.iotkit.mq.vertx.VertxMqConsumer;
import cc.iotkit.mq.vertx.VertxMqProducer;
import cc.iotkit.ruleengine.handler.RuleDeviceConsumer; import cc.iotkit.ruleengine.handler.RuleDeviceConsumer;
import cc.iotkit.ruleengine.rule.RuleMessageHandler; import cc.iotkit.ruleengine.rule.RuleMessageHandler;
import cc.iotkit.ruleengine.task.TaskManager; import cc.iotkit.ruleengine.task.TaskManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -32,12 +27,6 @@ public class RuleConfiguration {
return new RuleDeviceConsumer(consumer, Collections.singletonList(ruleMessageHandler)); return new RuleDeviceConsumer(consumer, Collections.singletonList(ruleMessageHandler));
} }
@ConditionalOnMissingBean
@Bean
public MqConsumer<ThingModelMessage> getThingModelMessageConsumer() {
return new VertxMqConsumer<>(ThingModelMessage.class);
}
@Bean @Bean
public TaskManager getTaskManager() { public TaskManager getTaskManager() {
return new TaskManager(); return new TaskManager();

View File

@ -1,3 +1,12 @@
/*
* +----------------------------------------------------------------------
* | Copyright (c) 2021-2022 All rights reserved.
* +----------------------------------------------------------------------
* | Licensed
* +----------------------------------------------------------------------
* | Author: xw2sy@163.com
* +----------------------------------------------------------------------
*/
package cc.iotkit.ruleengine.expression; package cc.iotkit.ruleengine.expression;

Binary file not shown.

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -123,9 +123,21 @@
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-message-bus</artifactId> <artifactId>iot-message-core</artifactId>
</dependency> </dependency>
<!--内置vertx消息总线-->
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-vertx-event-bus</artifactId>
</dependency>
<!--打开注释使用rocketmq消息总线-->
<!-- <dependency>-->
<!-- <groupId>cc.iotkit</groupId>-->
<!-- <artifactId>iot-message-rocketmq</artifactId>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-temporal-service</artifactId> <artifactId>iot-temporal-service</artifactId>
@ -137,17 +149,17 @@
</dependency> </dependency>
<!--打开注释 启用es数据库--> <!--打开注释 启用es数据库-->
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-es-temporal-service</artifactId>
</dependency>
<!--打开注释 启用tdengine数据库-->
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>cc.iotkit</groupId>--> <!-- <groupId>cc.iotkit</groupId>-->
<!-- <artifactId>iot-td-temporal-service</artifactId>--> <!-- <artifactId>iot-es-temporal-service</artifactId>-->
<!-- </dependency>--> <!-- </dependency>-->
<!--打开注释 启用tdengine数据库-->
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-td-temporal-service</artifactId>
</dependency>
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-data-cache</artifactId> <artifactId>iot-data-cache</artifactId>

View File

@ -104,7 +104,7 @@ public class ProductController {
dbStructureData.defineThingModel(thingModel); dbStructureData.defineThingModel(thingModel);
} else { } else {
//更新时序数据库物模型数据结构 //更新时序数据库物模型数据结构
dbStructureData.undefineThingModel(thingModel); dbStructureData.updateThingModel(thingModel);
} }
thingModelData.save(thingModel); thingModelData.save(thingModel);
} }

View File

@ -55,22 +55,22 @@ spring:
# ============mysql配置结束============>> # ============mysql配置结束============>>
#<<================es时序数据配置开始=============== #<<================es时序数据配置开始===============
# elasticsearch: elasticsearch:
# rest: rest:
# #使用内置es的配置 #使用内置es的配置
# #uris: http://elasticsearch:9200 #uris: http://elasticsearch:9200
# uris: http://127.0.0.1:9200 uris: http://127.0.0.1:9200
# username: username:
# password: password:
# connection-timeout: 10s connection-timeout: 10s
#================es时序数据配置结束===============>> #================es时序数据配置结束===============>>
#<<===========tdengine时序数据库配置开始============ #<<===========tdengine时序数据库配置开始============
td-datasource: # td-datasource:
url: jdbc:TAOS-RS://127.0.0.1:6041/iotkit?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8 # url: jdbc:TAOS-RS://127.0.0.1:6041/iotkit?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
username: root # username: root
password: taosdata # password: taosdata
driverClassName: com.taosdata.jdbc.rs.RestfulDriver # driverClassName: com.taosdata.jdbc.rs.RestfulDriver
#===========tdengine时序数据库配置开始============>> #===========tdengine时序数据库配置开始============>>
@ -86,6 +86,12 @@ spring:
pathmatch: pathmatch:
matching-strategy: ant_path_matcher matching-strategy: ant_path_matcher
#application.yml中打开注释支持rocketMq作为消息总线pom.xml中打开注释使用rocketmq消息总线
#rocketmq:
# name-server: 127.0.0.1:9876
# producer:
# group: iotkit
#图片存储用的是阿里云oss如果需要上传产品图片才需要配置 #图片存储用的是阿里云oss如果需要上传产品图片才需要配置
aliyun: aliyun:
bucketId: bucketId:

View File

@ -67,6 +67,12 @@ aliyun:
accessKeyId: accessKeyId:
accessKeySecret: accessKeySecret:
#application.yml中打开注释支持rocketMq作为消息总线pom.xml中打开注释使用rocketmq消息总线
#rocketmq:
# name-server: 127.0.0.1:9876
# producer:
# group: iotkit
sa-token: sa-token:
# token名称 (同时也是cookie名称) # token名称 (同时也是cookie名称)
token-name: token token-name: token

View File

@ -86,6 +86,12 @@ spring:
pathmatch: pathmatch:
matching-strategy: ant_path_matcher matching-strategy: ant_path_matcher
#application.yml中打开注释支持rocketMq作为消息总线pom.xml中打开注释使用rocketmq消息总线
#rocketmq:
# name-server: 172.16.1.113:9876
# producer:
# group: iotkit
#图片存储用的是阿里云oss如果需要上传产品图片才需要配置 #图片存储用的是阿里云oss如果需要上传产品图片才需要配置
aliyun: aliyun:
bucketId: bucketId:

BIN
iot-test-tool/iot-test-mqtt/.DS_Store vendored Normal file

Binary file not shown.

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iot-test-tool</artifactId> <artifactId>iot-test-tool</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -58,7 +58,7 @@
<configuration> <configuration>
<archive> <archive>
<manifest> <manifest>
<mainClass>cc.iotkit.simulator.Application</mainClass> <mainClass>cc.iotkit.test.mqtt.performance.ReportTest</mainClass>
</manifest> </manifest>
</archive> </archive>
<descriptorRefs> <descriptorRefs>

View File

@ -35,6 +35,7 @@ public class ReportTest {
if (args.length == 0) { if (args.length == 0) {
Mqtt.brokerHost = "127.0.0.1"; Mqtt.brokerHost = "127.0.0.1";
// Mqtt.brokerHost = "120.76.96.206"; // Mqtt.brokerHost = "120.76.96.206";
// Mqtt.brokerHost = "172.16.1.109";
} else { } else {
Mqtt.brokerHost = args[0]; Mqtt.brokerHost = args[0];
} }
@ -60,10 +61,6 @@ public class ReportTest {
"TEST_SC_" + StringUtils.leftPad(finalI + "", 6, "0"), "TEST_SC_" + StringUtils.leftPad(finalI + "", 6, "0"),
"S01"); "S01");
gateway.addSubDevice("xpsYHExTKPFaQMS7",
"TEST_LT_" + StringUtils.leftPad(finalI + "", 6, "0"),
"L01");
gateway.onDeviceOnline((device) -> { gateway.onDeviceOnline((device) -> {
String pk = device.getProductKey(); String pk = device.getProductKey();
if (!"Rf4QSjbm65X45753".equals(pk)) { if (!"Rf4QSjbm65X45753".equals(pk)) {

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>pom</packaging> <packaging>pom</packaging>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

17
pom.xml
View File

@ -14,7 +14,6 @@
<module>iot-message-bus</module> <module>iot-message-bus</module>
<module>iot-test-tool</module> <module>iot-test-tool</module>
<module>iot-data</module> <module>iot-data</module>
<module>iot-data/iot-td-temporal-service</module>
</modules> </modules>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -25,7 +24,7 @@
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iotkit-parent</artifactId> <artifactId>iotkit-parent</artifactId>
<version>0.4.1-SNAPSHOT</version> <version>0.4.2-SNAPSHOT</version>
<name>iotkit-parent</name> <name>iotkit-parent</name>
<description>iotkit parent</description> <description>iotkit parent</description>
<properties> <properties>
@ -271,7 +270,19 @@
<dependency> <dependency>
<groupId>cc.iotkit</groupId> <groupId>cc.iotkit</groupId>
<artifactId>iot-message-bus</artifactId> <artifactId>iot-message-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-vertx-event-bus</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-message-rocketmq</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>