diff --git a/.gitee/ISSUE_TEMPLATE.zh-CN.md b/.gitee/ISSUE_TEMPLATE.zh-CN.md old mode 100644 new mode 100755 diff --git a/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md b/.gitee/PULL_REQUEST_TEMPLATE.zh-CN.md old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.en.md b/README.en.md old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/http-plugin/pom.xml b/http-plugin/pom.xml old mode 100644 new mode 100755 index 56cd2a8..4546b78 --- a/http-plugin/pom.xml +++ b/http-plugin/pom.xml @@ -10,6 +10,7 @@ 4.0.0 http-plugin + 1.0.0 @@ -61,13 +62,13 @@ http-plugin cc.iotkit.plugins.http.Application - 1.0.0 + ${project.version} iita - http示例插件 + http示例插件,配置参数:端口(port)默认9081 application.yml - jar-outer + jar diff --git a/http-plugin/src/main/java/cc/iotkit/plugins/http/conf/BeanConfig.java b/http-plugin/src/main/java/cc/iotkit/plugins/http/conf/BeanConfig.java old mode 100644 new mode 100755 index aa18494..ebc0451 --- a/http-plugin/src/main/java/cc/iotkit/plugins/http/conf/BeanConfig.java +++ b/http-plugin/src/main/java/cc/iotkit/plugins/http/conf/BeanConfig.java @@ -1,5 +1,7 @@ package cc.iotkit.plugins.http.conf; +import cc.iotkit.plugin.core.IPluginConfig; +import cc.iotkit.plugin.core.LocalPluginConfig; import cc.iotkit.plugin.core.thing.IThingService; import cc.iotkit.plugins.http.service.FakeThingService; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -18,4 +20,10 @@ public class BeanConfig { return new FakeThingService(); } + @Bean + @ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev") + IPluginConfig getPluginConfig(){ + return new LocalPluginConfig(); + } + } diff --git a/http-plugin/src/main/java/cc/iotkit/plugins/http/service/FakeThingService.java b/http-plugin/src/main/java/cc/iotkit/plugins/http/service/FakeThingService.java old mode 100644 new mode 100755 diff --git a/http-plugin/src/main/java/cc/iotkit/plugins/http/service/HttpDevice.java b/http-plugin/src/main/java/cc/iotkit/plugins/http/service/HttpDevice.java old mode 100644 new mode 100755 diff --git a/http-plugin/src/main/java/cc/iotkit/plugins/http/service/HttpPlugin.java b/http-plugin/src/main/java/cc/iotkit/plugins/http/service/HttpPlugin.java old mode 100644 new mode 100755 index 45696a7..7faa65b --- a/http-plugin/src/main/java/cc/iotkit/plugins/http/service/HttpPlugin.java +++ b/http-plugin/src/main/java/cc/iotkit/plugins/http/service/HttpPlugin.java @@ -1,5 +1,11 @@ package cc.iotkit.plugins.http.service; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.plugin.core.IPluginConfig; +import cc.iotkit.plugins.http.conf.HttpConfig; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; +import com.gitee.starblues.bootstrap.annotation.AutowiredType; import com.gitee.starblues.bootstrap.realize.PluginCloseListener; import com.gitee.starblues.core.PluginCloseType; import com.gitee.starblues.core.PluginInfo; @@ -11,6 +17,7 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import java.util.Map; import java.util.concurrent.CountDownLatch; /** @@ -24,6 +31,12 @@ public class HttpPlugin implements PluginCloseListener { private PluginInfo pluginInfo; @Autowired private HttpVerticle httpVerticle; + @Autowired + private HttpConfig httpConfig; + + @Autowired + @AutowiredType(AutowiredType.Type.MAIN_PLUGIN) + private IPluginConfig pluginConfig; private Vertx vertx; private CountDownLatch countDownLatch; @@ -33,6 +46,12 @@ public class HttpPlugin implements PluginCloseListener { public void init() { vertx = Vertx.vertx(); try { + //获取插件最新配置替换当前配置 + Map config = pluginConfig.getConfig(pluginInfo.getPluginId()); + log.info("get config:{}", JsonUtils.toJsonString(config)); + BeanUtil.copyProperties(config, httpConfig, CopyOptions.create().ignoreNullValue()); + httpVerticle.setConfig(httpConfig); + countDownLatch = new CountDownLatch(1); Future future = vertx.deployVerticle(httpVerticle); future.onSuccess((s -> { @@ -41,12 +60,12 @@ public class HttpPlugin implements PluginCloseListener { })); future.onFailure((e) -> { countDownLatch.countDown(); - log.error("start mqtt plugin failed", e); + log.error("start http plugin failed", e); }); countDownLatch.await(); future.succeeded(); } catch (Throwable e) { - log.error("start mqtt plugin error.", e); + log.error("start http plugin error.", e); } } @@ -55,7 +74,7 @@ public class HttpPlugin implements PluginCloseListener { try { httpVerticle.stop(); Future future = vertx.undeploy(deployedId); - future.onSuccess(unused -> log.info("stop mqtt plugin success")); + future.onSuccess(unused -> log.info("stop http plugin success")); if (closeType == PluginCloseType.UNINSTALL) { log.info("插件被卸载了:{}", pluginInfo.getPluginId()); } else if (closeType == PluginCloseType.STOP) { @@ -64,7 +83,7 @@ public class HttpPlugin implements PluginCloseListener { log.info("插件被升级卸载了:{}", pluginInfo.getPluginId()); } } catch (Throwable e) { - log.error("stop mqtt plugin error.", e); + log.error("stop http plugin error.", e); } } diff --git a/http-plugin/src/main/java/cc/iotkit/plugins/http/service/HttpVerticle.java b/http-plugin/src/main/java/cc/iotkit/plugins/http/service/HttpVerticle.java index 63e8398..3b945a3 100755 --- a/http-plugin/src/main/java/cc/iotkit/plugins/http/service/HttpVerticle.java +++ b/http-plugin/src/main/java/cc/iotkit/plugins/http/service/HttpVerticle.java @@ -29,6 +29,7 @@ import io.vertx.core.json.JsonObject; import io.vertx.ext.web.Router; import io.vertx.ext.web.RoutingContext; import io.vertx.ext.web.handler.BodyHandler; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -46,9 +47,9 @@ import java.util.UUID; */ @Slf4j @Component +@Data public class HttpVerticle extends AbstractVerticle implements Handler { - @Autowired private HttpConfig config; @Autowired @@ -60,9 +61,11 @@ public class HttpVerticle extends AbstractVerticle implements Handler DEVICE_ONLINE = new HashSet<>(); + private HttpServer httpServer; + @Override public void start() { - HttpServer httpServer = vertx.createHttpServer(); + httpServer = vertx.createHttpServer(); Router router = Router.router(vertx); router.route().handler(BodyHandler.create()).handler(this); httpServer.requestHandler(router).listen(config.getPort(), ar -> { @@ -74,6 +77,11 @@ public class HttpVerticle extends AbstractVerticle implements Handler log.info("http server close result:{}", r.succeeded())); + } + @Override public void handle(RoutingContext ctx) { HttpServerResponse response = ctx.response(); diff --git a/http-plugin/src/main/resources/application.yml b/http-plugin/src/main/resources/application.yml old mode 100644 new mode 100755 diff --git a/http-plugin/src/main/resources/config.json b/http-plugin/src/main/resources/config.json new file mode 100644 index 0000000..106fb5c --- /dev/null +++ b/http-plugin/src/main/resources/config.json @@ -0,0 +1,26 @@ +[ + { + "id": "port", + "name": "端口", + "type": "number", + "value": 9081, + "desc": "http端口,默认为9081" + }, + { + "id": "a", + "name": "测试参数1", + "type": "radio", + "value": 0, + "desc": "单选参数a", + "options": [ + { + "name": "值0", + "value": 0 + }, + { + "name": "值1", + "value": 11 + } + ] + } +] \ No newline at end of file diff --git a/modbus-plugin/pom.xml b/modbus-plugin/pom.xml new file mode 100644 index 0000000..c3c2eab --- /dev/null +++ b/modbus-plugin/pom.xml @@ -0,0 +1,73 @@ + + + + iot-iita-plugins + cc.iotkit.plugins + 1.0.0 + + 4.0.0 + + modbus-plugin + + + + + com.digitalpetri.modbus + modbus-master-tcp + 1.2.0 + + + + + + + dev + + true + + + dev + + + + + prod + + prod + + + + + + + + com.gitee.starblues + spring-brick-maven-packager + + ${plugin.build.mode} + + modbus-plugin + cc.iotkit.plugins.modbus.Application + ${project.version} + iita + modbus示例插件 + application.yml + + + jar + + + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/Application.java b/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/Application.java new file mode 100755 index 0000000..34e50a0 --- /dev/null +++ b/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/Application.java @@ -0,0 +1,21 @@ +package cc.iotkit.plugins.modbus; + +import com.gitee.starblues.bootstrap.SpringPluginBootstrap; +import com.gitee.starblues.bootstrap.annotation.OneselfConfig; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * @author sjg + */ +@SpringBootApplication(scanBasePackages = {"cc.iotkit.plugin.core", "cc.iotkit.plugins.modbus"}) +@OneselfConfig(mainConfigFileName = {"application.yml"}) +@EnableConfigurationProperties +@EnableScheduling +public class Application extends SpringPluginBootstrap { + + public static void main(String[] args) { + new Application().run(Application.class, args); + } +} diff --git a/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/conf/BeanConfig.java b/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/conf/BeanConfig.java new file mode 100755 index 0000000..f81d639 --- /dev/null +++ b/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/conf/BeanConfig.java @@ -0,0 +1,36 @@ +package cc.iotkit.plugins.modbus.conf; + +import cc.iotkit.plugin.core.IPluginConfig; +import cc.iotkit.plugin.core.IPluginScript; +import cc.iotkit.plugin.core.LocalPluginConfig; +import cc.iotkit.plugin.core.LocalPluginScript; +import cc.iotkit.plugin.core.thing.IThingService; +import cc.iotkit.plugins.modbus.service.FakeThingService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +/** + * @author sjg + */ +@Component +public class BeanConfig { + + @Bean + @ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev") + IThingService getThingService() { + return new FakeThingService(); + } + + @Bean + @ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev") + IPluginScript getPluginScript() { + return new LocalPluginScript("test.js"); + } + + @Bean + @ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev") + IPluginConfig getPluginConfig(){ + return new LocalPluginConfig(); + } +} diff --git a/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/service/FakeThingService.java b/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/service/FakeThingService.java new file mode 100755 index 0000000..e1c4874 --- /dev/null +++ b/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/service/FakeThingService.java @@ -0,0 +1,47 @@ +package cc.iotkit.plugins.modbus.service; + +import cc.iotkit.model.device.DeviceInfo; +import cc.iotkit.model.product.Product; +import cc.iotkit.plugin.core.thing.IThingService; +import cc.iotkit.plugin.core.thing.actions.ActionResult; +import cc.iotkit.plugin.core.thing.actions.IDeviceAction; +import lombok.extern.slf4j.Slf4j; + +import java.util.HashMap; +import java.util.Map; + +/** + * 测试服务 + * + * @author sjg + */ +@Slf4j +public class FakeThingService implements IThingService { + + @Override + public ActionResult post(String pluginId, IDeviceAction action) { + log.info("post action:{}", action); + return ActionResult.builder().code(0).build(); + } + + @Override + public Product getProduct(String pk) { + return Product.builder() + .productKey("cGCrkK7Ex4FESAwe") + .productSecret("aaaaaaaa") + .build(); + } + + @Override + public DeviceInfo getDevice(String dn) { + return DeviceInfo.builder() + .productKey("cGCrkK7Ex4FESAwe") + .deviceName(dn) + .build(); + } + + @Override + public Map getProperty(String dn) { + return new HashMap<>(0); + } +} diff --git a/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/service/ModbusPlugin.java b/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/service/ModbusPlugin.java new file mode 100755 index 0000000..5700d63 --- /dev/null +++ b/modbus-plugin/src/main/java/cc/iotkit/plugins/modbus/service/ModbusPlugin.java @@ -0,0 +1,138 @@ +package cc.iotkit.plugins.modbus.service; + +import cc.iotkit.plugin.core.IPluginScript; +import cc.iotkit.plugin.core.thing.IThingService; +import cc.iotkit.plugin.core.thing.actions.DeviceState; +import cc.iotkit.plugin.core.thing.actions.up.DeviceRegister; +import cc.iotkit.plugin.core.thing.actions.up.DeviceStateChange; +import cc.iotkit.plugin.core.thing.actions.up.PropertyReport; +import cc.iotkit.script.IScriptEngine; +import com.digitalpetri.modbus.master.ModbusTcpMaster; +import com.digitalpetri.modbus.master.ModbusTcpMasterConfig; +import com.digitalpetri.modbus.requests.ReadHoldingRegistersRequest; +import com.digitalpetri.modbus.responses.ReadHoldingRegistersResponse; +import com.fasterxml.jackson.core.type.TypeReference; +import com.gitee.starblues.bootstrap.annotation.AutowiredType; +import com.gitee.starblues.bootstrap.realize.PluginCloseListener; +import com.gitee.starblues.core.PluginCloseType; +import com.gitee.starblues.core.PluginInfo; +import io.netty.buffer.ByteBufUtil; +import io.netty.util.ReferenceCountUtil; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.support.GenericApplicationContext; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import java.util.*; +import java.util.concurrent.CompletableFuture; + +/** + * @author sjg + */ +@Slf4j +@Service +public class ModbusPlugin implements PluginCloseListener { + + @Autowired + private PluginInfo pluginInfo; + + @Autowired + @AutowiredType(AutowiredType.Type.MAIN_PLUGIN) + private IPluginScript pluginScript; + + @Autowired + @AutowiredType(AutowiredType.Type.MAIN_PLUGIN) + private IThingService thingService; + + private IScriptEngine scriptEngine; + + private final ModbusTcpMasterConfig config = new ModbusTcpMasterConfig.Builder("localhost").setPort(502).build(); + private ModbusTcpMaster master; + + private final Set registeredDevice = new HashSet<>(); + + private final int[] slaves = new int[]{1, 2, 3}; + + private final Map DATA_CACHE = new HashMap<>(); + + @PostConstruct + public void init() { + master = new ModbusTcpMaster(config); + CompletableFuture connect = master.connect(); + connect.thenAccept(modbusTcpMaster -> System.out.println("111:" + modbusTcpMaster.getConfig())); + + //获取脚本引擎 + scriptEngine = pluginScript.getScriptEngine(pluginInfo.getPluginId()); + } + + @Scheduled(initialDelay = 3000, fixedDelay = 1000) + public void taskRead() { + for (int slave : slaves) { + CompletableFuture future = + master.sendRequest(new ReadHoldingRegistersRequest(0, 10), slave); + + future.thenAccept(response -> { + String rspBytes = ByteBufUtil.hexDump(response.getRegisters()); + ReferenceCountUtil.release(response); + + log.info("receive Response: " + rspBytes); + //相同数据不处理 + if (DATA_CACHE.getOrDefault(slave, "").equals(rspBytes)) { + return; + } + DATA_CACHE.put(slave, rspBytes); + + if (!registeredDevice.contains(slave)) { + //第一次读取自动注册设备 + thingService.post(pluginInfo.getPluginId(), DeviceRegister.builder() + .id(UUID.randomUUID().toString()) + .productKey("cGCrkK7Ex4FESAwe") + .deviceName(String.format("modbus_%d", slave)) + .build()); + registeredDevice.add(slave); + //并上线 + thingService.post(pluginInfo.getPluginId(), DeviceStateChange.builder() + .id(UUID.randomUUID().toString()) + .productKey("cGCrkK7Ex4FESAwe") + .deviceName(String.format("modbus_%d", slave)) + .state(DeviceState.ONLINE) + .build()); + } + + //调用脚本解码 + Map rst = scriptEngine.invokeMethod(new TypeReference<>() { + }, "decode", rspBytes); + if (rst == null || rst.isEmpty()) { + return; + } + + //属性上报 + thingService.post(pluginInfo.getPluginId(), PropertyReport.builder() + .id(UUID.randomUUID().toString()) + .productKey("cGCrkK7Ex4FESAwe") + .deviceName(String.format("modbus_%d", slave)) + .params(rst) + .build()); + }); + } + } + + @Override + public void close(GenericApplicationContext applicationContext, PluginInfo pluginInfo, PluginCloseType closeType) { + try { + master.disconnect(); + if (closeType == PluginCloseType.UNINSTALL) { + log.info("插件被卸载了:{}", pluginInfo.getPluginId()); + } else if (closeType == PluginCloseType.STOP) { + log.info("插件被关闭了:{}", pluginInfo.getPluginId()); + } else if (closeType == PluginCloseType.UPGRADE_UNINSTALL) { + log.info("插件被升级卸载了:{}", pluginInfo.getPluginId()); + } + } catch (Throwable e) { + log.error("stop mqtt plugin error.", e); + } + } + +} diff --git a/modbus-plugin/src/main/resources/application.yml b/modbus-plugin/src/main/resources/application.yml new file mode 100755 index 0000000..3fb99fe --- /dev/null +++ b/modbus-plugin/src/main/resources/application.yml @@ -0,0 +1,5 @@ +plugin: + runMode: dev + mainPackage: cc.iotkit.plugin + + diff --git a/modbus-plugin/src/main/resources/test.js b/modbus-plugin/src/main/resources/test.js new file mode 100644 index 0000000..41f2c62 --- /dev/null +++ b/modbus-plugin/src/main/resources/test.js @@ -0,0 +1,24 @@ +function hexToByte(hexString) { + if (hexString.length % 2 !== 0) { + throw new Error('Invalid hex string. String must have an even number of characters.'); + } + + let byteArray = []; + for (let i = 0; i < hexString.length; i += 4) { + byteArray.push(parseInt(hexString.substr(i, 4), 16)); + } + + return byteArray; +} + +this.decode=function(hex){ + try{ + const bytes=hexToByte(hex); + return { + "rssi":bytes[0], + "powerstate":bytes[1] + }; + }catch(e){ + return {}; + } +} \ No newline at end of file diff --git a/mqtt-plugin/pom.xml b/mqtt-plugin/pom.xml old mode 100644 new mode 100755 index b10d75c..9eabbce --- a/mqtt-plugin/pom.xml +++ b/mqtt-plugin/pom.xml @@ -66,13 +66,13 @@ mqtt-plugin cc.iotkit.plugins.mqtt.Application - 1.0.0 + ${project.version} iita mqtt示例插件 application.yml - jar-outer + jar diff --git a/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/conf/BeanConfig.java b/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/conf/BeanConfig.java old mode 100644 new mode 100755 index f0b684c..c72f817 --- a/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/conf/BeanConfig.java +++ b/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/conf/BeanConfig.java @@ -1,5 +1,7 @@ package cc.iotkit.plugins.mqtt.conf; +import cc.iotkit.plugin.core.IPluginConfig; +import cc.iotkit.plugin.core.LocalPluginConfig; import cc.iotkit.plugin.core.thing.IThingService; import cc.iotkit.plugins.mqtt.service.FakeThingService; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -18,4 +20,9 @@ public class BeanConfig { return new FakeThingService(); } + @Bean + @ConditionalOnProperty(name = "plugin.runMode", havingValue = "dev") + IPluginConfig getPluginConfig(){ + return new LocalPluginConfig(); + } } diff --git a/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/FakeThingService.java b/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/FakeThingService.java old mode 100644 new mode 100755 diff --git a/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/MqttDevice.java b/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/MqttDevice.java old mode 100644 new mode 100755 diff --git a/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/MqttPlugin.java b/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/MqttPlugin.java old mode 100644 new mode 100755 index 073d988..829d108 --- a/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/MqttPlugin.java +++ b/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/MqttPlugin.java @@ -1,5 +1,12 @@ package cc.iotkit.plugins.mqtt.service; +import cc.iotkit.common.utils.JsonUtils; +import cc.iotkit.plugin.core.IPlugin; +import cc.iotkit.plugin.core.IPluginConfig; +import cc.iotkit.plugins.mqtt.conf.MqttConfig; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; +import com.gitee.starblues.bootstrap.annotation.AutowiredType; import com.gitee.starblues.bootstrap.realize.PluginCloseListener; import com.gitee.starblues.core.PluginCloseType; import com.gitee.starblues.core.PluginInfo; @@ -11,6 +18,7 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import java.util.Map; import java.util.concurrent.CountDownLatch; /** @@ -18,12 +26,18 @@ import java.util.concurrent.CountDownLatch; */ @Slf4j @Service -public class MqttPlugin implements PluginCloseListener { +public class MqttPlugin implements PluginCloseListener, IPlugin { @Autowired private PluginInfo pluginInfo; @Autowired private MqttVerticle mqttVerticle; + @Autowired + private MqttConfig mqttConfig; + + @Autowired + @AutowiredType(AutowiredType.Type.MAIN_PLUGIN) + private IPluginConfig pluginConfig; private Vertx vertx; private CountDownLatch countDownLatch; @@ -33,6 +47,11 @@ public class MqttPlugin implements PluginCloseListener { public void init() { vertx = Vertx.vertx(); try { + //获取插件最新配置替换当前配置 + Map config = pluginConfig.getConfig(pluginInfo.getPluginId()); + BeanUtil.copyProperties(config,mqttConfig, CopyOptions.create().ignoreNullValue()); + mqttVerticle.setConfig(mqttConfig); + countDownLatch = new CountDownLatch(1); Future future = vertx.deployVerticle(mqttVerticle); future.onSuccess((s -> { @@ -68,4 +87,8 @@ public class MqttPlugin implements PluginCloseListener { } } + @Override + public Map getLinkInfo(String pk, String dn) { + return null; + } } diff --git a/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/MqttVerticle.java b/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/MqttVerticle.java index b0a6e34..3949138 100755 --- a/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/MqttVerticle.java +++ b/mqtt-plugin/src/main/java/cc/iotkit/plugins/mqtt/service/MqttVerticle.java @@ -34,6 +34,7 @@ import io.vertx.core.json.JsonObject; import io.vertx.core.net.PemKeyCertOptions; import io.vertx.mqtt.*; import io.vertx.mqtt.messages.codes.MqttSubAckReasonCode; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -52,6 +53,7 @@ import java.util.concurrent.ConcurrentHashMap; */ @Slf4j @Component +@Data public class MqttVerticle extends AbstractVerticle implements Handler { private MqttServer mqttServer; @@ -61,7 +63,6 @@ public class MqttVerticle extends AbstractVerticle implements Handler MQTT_CONNECT_POOL = new ConcurrentHashMap<>(); - @Autowired private MqttConfig config; @Autowired diff --git a/mqtt-plugin/src/main/resources/application.yml b/mqtt-plugin/src/main/resources/application.yml old mode 100644 new mode 100755 diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 index 599aae3..c989671 --- a/pom.xml +++ b/pom.xml @@ -6,6 +6,7 @@ mqtt-plugin http-plugin + modbus-plugin