Skip to content

Commit e37fe89

Browse files
committed
feat: add own configuration to the plugin
1 parent bab27f2 commit e37fe89

14 files changed

+1074
-278
lines changed

docker-compose.yml

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
services:
2-
emqx:
3-
image: emqx/emqx-enterprise:5.8.4
4-
container_name: emqx
5-
environment:
6-
EMQX_LOG__CONSOLE__LEVEL: debug
7-
EMQX_API_KEY__BOOTSTRAP_FILE: "/opt/emqx-bootstrap/api-keys.txt"
8-
ports:
9-
- "1883:1883"
10-
- "18083:18083"
11-
networks:
12-
- emqx_network
13-
healthcheck:
14-
test: ["CMD", "/opt/emqx/bin/emqx", "ctl", "status"]
15-
interval: 5s
16-
timeout: 25s
17-
retries: 5
18-
volumes:
19-
- ./test/assets/api-keys.txt:/opt/emqx-bootstrap/api-keys.txt
20-
depends_on:
21-
mysql:
22-
condition: service_healthy
23-
redis:
24-
condition: service_healthy
2+
# emqx:
3+
# image: emqx/emqx-enterprise:5.8.4
4+
# container_name: emqx
5+
# environment:
6+
# EMQX_LOG__CONSOLE__LEVEL: debug
7+
# EMQX_API_KEY__BOOTSTRAP_FILE: "/opt/emqx-bootstrap/api-keys.txt"
8+
# ports:
9+
# - "1883:1883"
10+
# - "18083:18083"
11+
# networks:
12+
# - emqx_network
13+
# healthcheck:
14+
# test: ["CMD", "/opt/emqx/bin/emqx", "ctl", "status"]
15+
# interval: 5s
16+
# timeout: 25s
17+
# retries: 5
18+
# volumes:
19+
# - ./test/assets/api-keys.txt:/opt/emqx-bootstrap/api-keys.txt
20+
# depends_on:
21+
# mysql:
22+
# condition: service_healthy
23+
# redis:
24+
# condition: service_healthy
2525

2626
mysql:
2727
image: mysql:8.0

docker/mysql/docker-entrypoint-initdb.d/init.sql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,12 @@ CREATE TABLE `mqtt_msg` (
1010
`arrived` datetime NOT NULL,
1111
PRIMARY KEY (`id`),
1212
INDEX topic_index(`topic`)
13-
) ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;
13+
) ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;
14+
15+
DROP TABLE IF EXISTS `mqtt_sub`;
16+
CREATE TABLE `mqtt_sub` (
17+
`clientid` varchar(64) NOT NULL,
18+
`topic` varchar(180) NOT NULL,
19+
`qos` tinyint(1) NOT NULL DEFAULT '0',
20+
PRIMARY KEY (`clientid`, `topic`)
21+
) ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;

priv/_config_schema.avsc

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"type": "record",
3+
"name": "ExtendedConfig",
4+
"fields": [
5+
{
6+
"name": "hostname",
7+
"type": "string",
8+
"default": "localhost",
9+
"$ui": {
10+
"component": "input",
11+
"flex": 12,
12+
"required": true,
13+
"label": "$hostname_label",
14+
"description": "$hostname_desc",
15+
"rules": [
16+
{
17+
"type": "pattern",
18+
"pattern": "^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])(\\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9]))*$",
19+
"message": "$hostname_validate"
20+
}
21+
]
22+
}
23+
},
24+
{
25+
"name": "port",
26+
"type": "int",
27+
"default": 3306,
28+
"$ui": {
29+
"component": "input-number",
30+
"flex": 12,
31+
"required": true,
32+
"label": "$port_label",
33+
"description": "$port_desc",
34+
"rules": [
35+
{
36+
"type": "range",
37+
"min": 1,
38+
"max": 65535,
39+
"message": "$port_range_validate"
40+
}
41+
]
42+
}
43+
},
44+
{
45+
"name": "connectionOptions",
46+
"type": {
47+
"type": "array",
48+
"items": {
49+
"type": "record",
50+
"name": "ConnectionOption",
51+
"fields": [
52+
{
53+
"name": "optionName",
54+
"type": "string"
55+
},
56+
{
57+
"name": "optionValue",
58+
"type": "string"
59+
},
60+
{
61+
"name": "optionType",
62+
"type": "string"
63+
}
64+
]
65+
}
66+
},
67+
"default": [
68+
{
69+
"optionName": "autoReconnect",
70+
"optionValue": "true",
71+
"optionType": "boolean"
72+
}
73+
],
74+
"$ui": {
75+
"component": "maps-editor",
76+
"flex": 24,
77+
"items": {
78+
"optionName": {
79+
"label": "$option_name_label",
80+
"description": "$option_name_desc",
81+
"type": "string"
82+
},
83+
"optionValue": {
84+
"label": "$option_value_label",
85+
"description": "$option_value_desc",
86+
"type": "string"
87+
}
88+
},
89+
"label": "$connection_options_label",
90+
"description": "$connection_options_desc"
91+
}
92+
},
93+
{
94+
"name": "auth",
95+
"type": {
96+
"type": "record",
97+
"name": "authConfigs",
98+
"fields": [
99+
{
100+
"name": "username",
101+
"type": "string",
102+
"$ui": {
103+
"component": "input",
104+
"flex": 12,
105+
"required": true,
106+
"label": "$username_label",
107+
"description": "$username_desc"
108+
}
109+
},
110+
{
111+
"name": "password",
112+
"type": [
113+
"null",
114+
"string"
115+
],
116+
"default": null,
117+
"$ui": {
118+
"component": "input-password",
119+
"flex": 12,
120+
"label": "$password_label",
121+
"description": "$password_desc",
122+
"rules": [
123+
{
124+
"type": "length",
125+
"minLength": 8,
126+
"maxLength": 128,
127+
"message": "$password_length_validate"
128+
},
129+
{
130+
"type": "pattern",
131+
"pattern": "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]*$",
132+
"message": "$password_validate"
133+
}
134+
]
135+
}
136+
}
137+
]
138+
}
139+
}
140+
]
141+
}

priv/config.hocon

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
redis {
2-
parameters {
3-
server = "redis"
4-
redis_type = "single"
5-
pool_size = 8
6-
password = "public"
7-
database = 0
8-
},
9-
resource_opts {
10-
health_check_interval = "15s"
11-
start_timeout = "5s"
12-
},
1+
mysql {
2+
enable = false
133
ssl {
144
enable = false
15-
verify = "verify_peer"
165
}
6+
server = "mysql:3306"
7+
pool_size = 8
8+
username = "emqx"
9+
password = "public"
10+
database = "emqx"
11+
insert_message_sql = "insert into mqtt_msg(msgid, sender, topic, qos, retain, payload, arrived) values(${id}, ${clientid}, ${topic}, ${qos}, ${retain}, ${payload}, FROM_UNIXTIME(${timestamp}/1000))"
12+
delete_message_sql = "delete from mqtt_msg where msgid = ${id}"
13+
select_message_sql = "select * from mqtt_msg where msgid = ${id}"
14+
insert_subscription_sql = "insert into mqtt_sub(clientid, topic, qos) values(${clientid}, ${topic}, ${qos}) on duplicate key update qos = ${qos}"
15+
select_subscriptions_sql = "select topic, qos from mqtt_sub where clientid = ${clientid}"
16+
}
17+
18+
redis {
19+
enable = false
1720
}
1821

1922

2023

2124

25+
26+

priv/config_i18n.json

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,122 @@
11
{
2+
"$mysql_enable_label": {
3+
"en": "Enable MySQL",
4+
"zh": "启用 MySQL"
5+
},
6+
"$mysql_enable_desc": {
7+
"en": "Enable MySQL integration",
8+
"zh": "启用 MySQL 集成"
9+
},
10+
"$mysql_insert_message_sql_label": {
11+
"en": "Insert Message SQL",
12+
"zh": "插入消息 SQL"
13+
},
14+
"$mysql_insert_message_sql_desc": {
15+
"en": "Insert Message SQL",
16+
"zh": "插入消息 SQL"
17+
},
18+
"$mysql_delete_message_sql_label": {
19+
"en": "Delete Message SQL",
20+
"zh": "删除消息 SQL"
21+
},
22+
"$mysql_delete_message_sql_desc": {
23+
"en": "Delete Message SQL",
24+
"zh": "删除消息 SQL"
25+
},
26+
"$mysql_select_message_sql_label": {
27+
"en": "Select Message SQL",
28+
"zh": "查询消息 SQL"
29+
},
30+
"$mysql_select_message_sql_desc": {
31+
"en": "Select Message SQL",
32+
"zh": "查询消息 SQL"
33+
},
34+
"$mysql_insert_subscription_sql_label": {
35+
"en": "Insert Subscription SQL",
36+
"zh": "插入订阅 SQL"
37+
},
38+
"$mysql_insert_subscription_sql_desc": {
39+
"en": "Insert Subscription SQL",
40+
"zh": "插入订阅 SQL"
41+
},
42+
"$mysql_select_subscriptions_sql_label": {
43+
"en": "Select Subscriptions SQL",
44+
"zh": "查询订阅 SQL"
45+
},
46+
"$mysql_select_subscriptions_sql_desc": {
47+
"en": "Select Subscriptions SQL",
48+
"zh": "查询订阅 SQL"
49+
},
50+
"$mysql_server_label": {
51+
"en": "MySQL Server",
52+
"zh": "MySQL 服务器"
53+
},
54+
"$mysql_server_desc": {
55+
"en": "MySQL Server",
56+
"zh": "MySQL 服务器"
57+
},
58+
"$mysql_database_label": {
59+
"en": "MySQL Database",
60+
"zh": "MySQL 数据库"
61+
},
62+
"$mysql_database_desc": {
63+
"en": "MySQL Database",
64+
"zh": "MySQL 数据库"
65+
},
66+
"$mysql_pool_size_label": {
67+
"en": "MySQL Pool Size",
68+
"zh": "MySQL 连接池大小"
69+
},
70+
"$mysql_pool_size_desc": {
71+
"en": "MySQL Pool Size",
72+
"zh": "MySQL 连接池大小"
73+
},
74+
"$mysql_username_label": {
75+
"en": "MySQL Username",
76+
"zh": "MySQL 用户名"
77+
},
78+
"$mysql_username_desc": {
79+
"en": "MySQL Username",
80+
"zh": "MySQL 用户名"
81+
},
82+
"$mysql_password_label": {
83+
"en": "MySQL Password",
84+
"zh": "MySQL 密码"
85+
},
86+
"$mysql_password_desc": {
87+
"en": "MySQL Password",
88+
"zh": "MySQL 密码"
89+
},
90+
"$mysql_batch_size_label": {
91+
"en": "MySQL Batch Size",
92+
"zh": "MySQL 批量大小"
93+
},
94+
"$mysql_batch_size_desc": {
95+
"en": "MySQL Batch Size",
96+
"zh": "MySQL 批量大小"
97+
},
98+
"$mysql_batch_time_label": {
99+
"en": "MySQL Batch Time (ms)",
100+
"zh": "MySQL 批量时间 (ms)"
101+
},
102+
"$mysql_batch_time_desc": {
103+
"en": "MySQL Batch Time (ms)",
104+
"zh": "MySQL 批量时间 (ms)"
105+
},
106+
"$mysql_ssl_enable_label": {
107+
"en": "MySQL SSL Enable",
108+
"zh": "MySQL SSL 启用"
109+
},
110+
"$mysql_ssl_enable_desc": {
111+
"en": "MySQL SSL Enable",
112+
"zh": "MySQL SSL 启用"
113+
},
114+
"$enable_redis_label": {
115+
"en": "Enable Redis",
116+
"zh": "启用 Redis"
117+
},
118+
"$enable_redis_desc": {
119+
"en": "Enable Redis integration",
120+
"zh": "启用 Redis 集成"
121+
}
2122
}

0 commit comments

Comments
 (0)