emqx-component增加对emqx5.0兼容

V0.5.x
xiwa 2023-04-15 07:16:07 +08:00
parent 5d2647f8a1
commit 6f7cf24770
5 changed files with 103 additions and 29 deletions

View File

@ -60,9 +60,6 @@ function acl(head,type,payload){
};
}
if (/^\/sys\/.+\/.+\/c\/#/i.test(_topic)) {
return subscribe(head,type,payload);
}
if (/^\/sys\/.+\/.+\/s\/.*/i.test(_topic)) {
return subscribe(head,type,payload);
}
@ -224,9 +221,6 @@ function subscribe(head,type,payload){
}
}
var messageHandler = {
"/sys/client/connected":connect,
"/sys/client/disconnected":disconnect,
@ -240,19 +234,9 @@ var messageHandler = {
this.onReceive=function(head,type,payload){
payload=JSON.parse(payload);
print("======================================================================= ");
print("【message from】: " + (isServerId(payload.clientid)?"Server":"Device") );
print("onReceive head: "+JSON.stringify(head));
print("onReceive type: "+JSON.stringify(type));
print("onReceive payload: "+ JSON.stringify(payload));
//print("onReceive compMqttClientIdList: "+ component.getCompMqttClientIdList());
var result = {};
var topic = head.topic;
if(!topic) {
print("【result】: " + JSON.stringify(result));
print("======================================================================= ");
return result;
}
@ -292,8 +276,6 @@ this.onReceive=function(head,type,payload){
}
}
print("【result】: " + JSON.stringify(result));
print("======================================================================= ");
return result;
}

View File

@ -13,6 +13,7 @@ import cc.iotkit.comp.IMessageHandler;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.handler.BodyHandler;
import lombok.extern.slf4j.Slf4j;
@ -27,7 +28,7 @@ public class AuthVerticle extends AbstractVerticle {
private IMessageHandler executor;
private EmqxConfig config;
private final EmqxConfig config;
public void setExecutor(IMessageHandler executor) {
this.executor = executor;
@ -38,7 +39,7 @@ public class AuthVerticle extends AbstractVerticle {
}
@Override
public void start() throws Exception {
public void start() {
backendServer = vertx.createHttpServer();
//第一步 声明Router&初始化Router
@ -54,11 +55,9 @@ public class AuthVerticle extends AbstractVerticle {
Map<String, Object> head = new HashMap<>();
head.put("topic", "/mqtt/auth");
executor.onReceive(head, "auth", json);
rc.response().setStatusCode(200)
.end();
httpResult(rc.response(), 200);
} catch (Throwable e) {
rc.response().setStatusCode(500)
.end();
httpResult(rc.response(), 500);
log.error("mqtt auth failed", e);
}
});
@ -69,12 +68,9 @@ public class AuthVerticle extends AbstractVerticle {
Map<String, Object> head = new HashMap<>();
head.put("topic", "/mqtt/acl");
executor.onReceive(head, "acl", json);
rc.response().setStatusCode(200)
.end();
httpResult(rc.response(), 200);
} catch (Throwable e) {
rc.response().setStatusCode(500)
.end();
httpResult(rc.response(), 500);
log.error("mqtt acl failed", e);
}
});
@ -82,6 +78,14 @@ public class AuthVerticle extends AbstractVerticle {
backendServer.requestHandler(backendRouter).listen(config.getAuthPort());
}
private void httpResult(HttpServerResponse response, int code) {
response.putHeader("Content-Type", "application/json");
response
.setStatusCode(code);
response
.end("{\"result\": \"" + (code == 200 ? "allow" : "deny") + "\"}");
}
@Override
public void stop() throws Exception {
backendServer.close(voidAsyncResult -> log.info("close emqx auth server..."));

View File

@ -0,0 +1,87 @@
<?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/maven-v4_0_0.xsd">
<parent>
<artifactId>iot-components</artifactId>
<groupId>cc.iotkit</groupId>
<version>0.4.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>iot-websocket-component</artifactId>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactSet>
<includes>
<include>io.vertx:vertx-core</include>
<include>org.luaj:luaj-jse</include>
</includes>
</artifactSet>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<useIncrementalCompilation>false</useIncrementalCompilation>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>4.2.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.luaj</groupId>
<artifactId>luaj-jse</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-common</artifactId>
<version>0.4.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-component-base</artifactId>
<version>0.4.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cc.iotkit</groupId>
<artifactId>iot-data-service</artifactId>
<version>0.4.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -19,6 +19,7 @@
<module>iot-component-base</module>
<module>iot-http-biz-component</module>
<module>iot-component-tcp</module>
<module>iot-websocket-component</module>
<!-- <module>iot-ctwing-component</module>-->
</modules>