打包方式修改

V0.5.x
xiwa 2022-11-28 08:27:10 +08:00
parent 3cedbda107
commit bb9ca476c8
16 changed files with 287 additions and 156 deletions

View File

@ -187,6 +187,16 @@ this.onReceive=function(head,type,payload){
})
}
};
var action={};
if(!topic.endsWith("_reply")){
//需要回复的消息
action={
type:"ack",
content:JSON.stringify(reply)
}
}
return {
type:"report",
data:{
@ -198,10 +208,7 @@ this.onReceive=function(head,type,payload){
payload:payload
}
},
action:{
type:"ack",
content:JSON.stringify(reply)
}
action:action
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 497 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

View File

@ -38,7 +38,8 @@ public class ComponentClassLoader {
classLoader.close();
}
classLoader = URLClassLoader.newInstance(new URL[]{jarPath.toURI().toURL()}, ClassLoader.getSystemClassLoader());
classLoader = URLClassLoader.newInstance(new URL[]{jarPath.toURI().toURL()},
Thread.currentThread().getContextClassLoader());
classLoaders.put(name, classLoader);
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);

View File

@ -48,7 +48,7 @@ function register(payload){
var dn=arr[1];
var model=arr[2];
var pwd=md5("xdkKUymrEGSCYWswqCvSPyRSFvH5j7CU"+auth.clientid);
if(pwd!=auth.password){
if(pwd.toLocaleLowerCase()!=auth.password.toLocaleLowerCase()){
throw new Error("incorrect password");
}
return {
@ -173,6 +173,30 @@ this.onReceive=function(head,type,payload){
}
//数据上报
var reply=
{
productKey:pk,
deviceName:dn,
mid:payload.id,
content:{
topic:topic.replace("/s/","/c/")+"_reply",
payload:JSON.stringify({
id:payload.id,
method: payload.method+"_reply",
code:0,
})
}
};
var action={};
if(!topic.endsWith("_reply")){
//需要回复的消息
action={
type:"ack",
content:JSON.stringify(reply)
}
}
return {
type:"report",
data:{
@ -183,7 +207,8 @@ this.onReceive=function(head,type,payload){
topic:topic,
payload:payload
}
}
},
action:action
}
}

View File

@ -1,104 +0,0 @@
var mid=1;
function getMid(){
mid++;
if(mid>10000){
mid=1;
}
return mid+"";
}
this.decode = function (msg) {
//对msg进行解析并返回物模型数据
var content=msg.content;
var topic = content.topic;
var payload = content.payload;
var identifier = topic.substring(topic.lastIndexOf("/") + 1);
if (topic.endsWith("/property/post")) {
//属性上报
return {
mid: msg.mid,
productKey: msg.productKey,
deviceName: msg.deviceName,
type:"property",
identifier: "report", //属性上报
occur: new Date().getTime(), //时间戳,设备上的事件或数据产生的本地时间
time: new Date().getTime(), //时间戳,消息上报时间
data: payload.params,
};
} else if (topic.indexOf("/event/") > 0) {
//事件上报
return {
mid: msg.mid,
productKey: msg.productKey,
deviceName: msg.deviceName,
type:"event",
identifier: identifier,
occur: new Date().getTime(),
time: new Date().getTime(),
data: payload.params,
};
}else if(topic.endsWith("/service/property/set_reply")){
//属性设置回复
return {
mid: msg.mid,
productKey: msg.productKey,
deviceName: msg.deviceName,
type:"property",
identifier: identifier,
occur: new Date().getTime(),
time: new Date().getTime(),
code: payload.code
};
} else if (topic.endsWith("_reply")) {
//服务回复
return {
mid: msg.mid,
productKey: msg.productKey,
deviceName: msg.deviceName,
type:"service",
identifier: identifier,
occur: new Date().getTime(),
time: new Date().getTime(),
code: payload.code,
data: payload.data,
};
}
return null;
};
this.encode = function (service,device) {
var type=service.type;
var identifier=service.identifier;
var topic="/sys/"+service.productKey+"/"+service.deviceName+"/c/service/";
var method="thing.service.";
if(type=="property"){
method+="property."+identifier;
topic+="property/"+identifier;
}else if(type=="service"){
method+=identifier;
topic+=identifier;
}
var deviceMid=getMid();
var params={};
for(var p in service.params){
params[p]=service.params[p];
}
return {
productKey:service.productKey,
deviceName:service.deviceName,
mid:deviceMid,
content:{
topic:topic,
payload:JSON.stringify({
id:deviceMid,
method:method,
params:params
})
}
}
};

View File

@ -3,10 +3,62 @@
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>standalone-package</id>
<formats>
<format>tar</format>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<!--
0755->即用户具有读/写/执行权限,组用户和其它用户具有读写权限;
0644->即用户具有读写权限,组用户和其它用户具有只读权限;
-->
<!-- 将assemblies/bin目录下的所有文件输出到打包后的bin目录中 -->
<fileSet>
<directory>${project.parent.basedir}/iot-standalone/src/main/bin</directory>
<outputDirectory>/bin</outputDirectory>
<includes>
<include>**/*.bat</include>
<include>**/*.sh</include>
</includes>
<fileMode>0755</fileMode>
<!--如果是脚本一定要改为unix.如果是在windows上面编码会出现dos编写问题-->
<lineEnding>unix</lineEnding>
<filtered>true</filtered><!-- 是否进行属性替换 -->
</fileSet>
<!-- 将/iot-standalone/src/main/resources下配置文件打包到config目录 -->
<fileSet>
<directory>${project.parent.basedir}/iot-standalone/src/main/resources</directory>
<outputDirectory>/config</outputDirectory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.yml</include>
</includes>
<filtered>true</filtered><!-- 是否进行属性替换 -->
</fileSet>
<!-- 将项目启动jar打包到lib目录中 -->
<fileSet>
<directory>target</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<!-- 将项目说明文档打包到docs目录中 -->
<fileSet>
<directory>${project.parent.basedir}</directory>
<outputDirectory>docs</outputDirectory>
<includes>
<include>*.md</include>
</includes>
<fileMode>0644</fileMode>
</fileSet>
<!--将初始化数据打包到data目录-->
<fileSet>
<directory>${project.parent.basedir}/data/components</directory>
<outputDirectory>data/components</outputDirectory>
@ -28,13 +80,6 @@
<include>**/*</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
</fileSets>
</assembly>

Binary file not shown.

View File

@ -181,6 +181,11 @@
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>

View File

@ -0,0 +1,38 @@
echo off
set APP_NAME=${project.build.finalName}.jar
set LOG_IMPL_FILE=log4j2.xml
set LOGGING_CONFIG=
if exist ../config/%LOG_IMPL_FILE% (
set LOGGING_CONFIG=-Dlogging.config=../config/%LOGGING_CONFIG%
)
set CONFIG= -Dlogging.path=../log %LOGGING_CONFIG% -Dspring.config.location=../config/
set DEBUG_OPTS=
if ""%1"" == ""debug"" (
set DEBUG_OPTS= -Xloggc:../log/gc.log -verbose:gc -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../log
goto debug
)
set JMX_OPTS=
if ""%1"" == ""jmx"" (
set JMX_OPTS= -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9888 -Dcom.sun.management.jmxremote.ssl=FALSE -Dcom.sun.management.jmxremote.authenticate=FALSE
goto jmx
)
echo "Starting the %APP_NAME%"
java -Xms512m -Xmx512m -server %DEBUG_OPTS% %JMX_OPTS% %CONFIG% -jar ../lib/%APP_NAME%
echo "java -Xms512m -Xmx512m -server %DEBUG_OPTS% %JMX_OPTS% %CONFIG% -jar ../lib/%APP_NAME%"
goto end
:debug
echo "debug"
java -Xms512m -Xmx512m -server %DEBUG_OPTS% %CONFIG% -jar ../lib/%APP_NAME%
goto end
:jmx
java -Xms512m -Xmx512m -server %JMX_OPTS% %CONFIG% -jar ../lib/%APP_NAME%
goto end
:end
pause

View File

@ -0,0 +1,109 @@
#!/bin/bash
# 项目名称
SERVER_NAME="${project.artifactId}"
# jar名称
JAR_NAME="${project.build.finalName}.jar"
# 进入bin目录
cd `dirname $0`
# bin目录绝对路径
BIN_DIR=`pwd`
# 返回到上一级项目根目录路径
cd ..
# 打印项目根目录绝对路径
# `pwd` 执行系统命令并获得结果
DEPLOY_DIR=`pwd`
# 外部配置文件绝对目录,如果是目录需要/结尾,也可以直接指定文件
# 如果指定的是目录,spring则会读取目录中的所有配置文件
CONF_DIR=$DEPLOY_DIR/config
# SERVER_PORT=`sed '/server.port/!d;s/.*=//' config/application.properties | tr -d '\r'`
# 获取应用的端口号
SERVER_PORT=`sed -nr '/port: [0-9]+/ s/.*port: +([0-9]+).*/\1/p' config/application.yml|head -1`
PIDS=`ps -f | grep java | grep "$CONF_DIR" |awk '{print $2}'`
if [ "$1" = "status" ]; then
if [ -n "$PIDS" ]; then
echo "The $SERVER_NAME is running...!"
echo "PID: $PIDS"
exit 0
else
echo "The $SERVER_NAME is stopped"
exit 0
fi
fi
if [ -n "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME already started!"
echo "PID: $PIDS"
exit 1
fi
if [ -n "$SERVER_PORT" ]; then
SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l`
if [ $SERVER_PORT_COUNT -gt 0 ]; then
echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!"
exit 1
fi
fi
# 项目日志输出绝对路径
LOGS_DIR=$DEPLOY_DIR/log
# 如果logs文件夹不存在,则创建文件夹
if [ ! -d $LOGS_DIR ]; then
mkdir $LOGS_DIR
fi
STDOUT_FILE=$LOGS_DIR/catalina.log
# JVM Configuration
JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true "
JAVA_DEBUG_OPTS=""
if [ "$1" = "debug" ]; then
JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "
fi
JAVA_JMX_OPTS=""
if [ "$1" = "jmx" ]; then
JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "
fi
JAVA_MEM_OPTS=""
BITS=`java -version 2>&1 | grep -i 64-bit`
if [ -n "$BITS" ]; then
JAVA_MEM_OPTS=" -server -Xmx512m -Xms512m -Xmn256m -Xss256k"
else
JAVA_MEM_OPTS=" -server -Xms512m -Xmx512m"
fi
# 加载外部log4j2文件的配置
LOG_IMPL_FILE=log4j2.xml
LOGGING_CONFIG=""
if [ -f "$CONF_DIR/$LOG_IMPL_FILE" ]
then
LOGGING_CONFIG="-Dlogging.config=$CONF_DIR/$LOG_IMPL_FILE"
fi
CONFIG_FILES=" -Dlogging.path=$LOGS_DIR $LOGGING_CONFIG -Dspring.config.location=$CONF_DIR/ "
echo -e "Starting the $SERVER_NAME ..."
nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS $CONFIG_FILES -jar $DEPLOY_DIR/lib/$JAR_NAME > $STDOUT_FILE 2>&1 &
COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
if [ -n "$SERVER_PORT" ]; then
COUNT=`netstat -an | grep $SERVER_PORT | wc -l`
else
COUNT=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`
fi
if [ $COUNT -gt 0 ]; then
break
fi
done
echo "OK!"
PIDS=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}'`
echo "PID: $PIDS"
echo "STDOUT: $STDOUT_FILE"

View File

@ -0,0 +1,18 @@
#!/bin/bash
# 项目名称
APPLICATION="${project.artifactId}"
# 项目启动jar包名称
APPLICATION_JAR="${project.build.finalName}.jar"
# 通过项目名称查找到PI然后kill -9 pid
PID=$(ps -ef | grep "${APPLICATION_JAR}" | grep -v grep | awk '{ print $2 }')
if [[ -z "$PID" ]]
then
echo ${APPLICATION} is already stopped
else
echo kill ${PID}
kill -9 ${PID}
echo ${APPLICATION} stopped successfully
fi

View File

@ -21,7 +21,10 @@ public class EmbeddedRedisConfig {
RedisServer redisServer;
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("windows")) {
redisServer = RedisServer.builder().setting("maxheap 200m").build();
redisServer = RedisServer.builder().setting("maxheap 200m")
.port(6379)
.setting("bind localhost")
.build();
} else {
redisServer = new RedisServer();
}

View File

@ -150,26 +150,7 @@ public class DeviceService {
//设备指令下发
deviceComponentManager.send(thingService);
}
String mid = thingService.getMid();
DeviceInfo device = deviceInfoData.findByDeviceId(deviceId);
//保存设备日志
ThingModelMessage thingModelMessage = ThingModelMessage.builder()
.mid(mid)
.deviceId(deviceId)
.productKey(pk)
.deviceName(dn)
.uid(device.getUid())
.type(type)
.identifier(identifier)
.data(data)
.occurred(System.currentTimeMillis())
.time(System.currentTimeMillis())
.build();
thingModelMessageData.add(thingModelMessage);
return mid;
return thingService.getMid();
}
}

View File

@ -20,5 +20,7 @@ public class Request {
private String id;
private String method;
private Object params;
}

View File

@ -33,8 +33,8 @@ public class ReportTest {
if (args.length == 0) {
Mqtt.brokerHost = "127.0.0.1";
// Mqtt.brokerHost = "120.76.96.206";
// Mqtt.brokerHost = "127.0.0.1";
Mqtt.brokerHost = "120.76.96.206";
// Mqtt.brokerHost = "172.16.1.109";
} else {
Mqtt.brokerHost = args[0];
@ -74,6 +74,7 @@ public class ReportTest {
() -> {
Request request = new Request();
request.setId(UUID.randomUUID().toString());
request.setMethod("thing.event.property.post");
Map<String, Object> param = new HashMap<>();
param.put("volt", Math.round(Math.random() * 100));
request.setParams(param);