mqtt server example

This commit is contained in:
Alexander Popov 2024-09-08 01:27:23 +03:00
parent 1dca56be86
commit 5c9771ff06
5 changed files with 185 additions and 0 deletions

2
projects/nanomq/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
jwtRS256.*
mqtt_client.*

26
projects/nanomq/README.md Normal file
View File

@ -0,0 +1,26 @@
# ...
## Генерация **jwtRS256** ключа
```sh
ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key # Don't add passphrase
openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
```
Команды ниже конвертируют ключи в однострочник
```sh
awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' jwtRS256.key
awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' jwtRS256.key.pub
```
## Отладка
Используйте приложение [mqttx](https://mqttx.app/) для отладки.
## Ссылки
* https://gist.github.com/ygotthilf/baa58da5c3dd1f69fae9

View File

@ -0,0 +1,96 @@
bridges.mqtt.emqx1 {
server = "mqtt-tcp://127.0.0.1:1883"
proto_ver = 5
keepalive = 60s
backoff_max = 60s
clean_start = false
username = username
password = passwd
conn_properties = {
maximum_packet_size = 1024
receive_maximum = 65535
topic_alias_maximum = 0
request_problem_infomation = 1
request_response_infomation = 0
session_expiry_interval = 0
user_property = {
key1 = value1
key2 = value2
}
}
will {
topic = "will_topic"
qos = 1
retain = false
payload = "will_message"
properties = {
payload_format_indicator = 0
message_expiry_interval = 0
content_type = ""
response_topic = ""
correlation_data = ""
will_delay_interval = 0
user_property = {
key1 = value1
key2 = value2
}
}
}
forwards = [
{
remote_topic = "fwd/topic1"
local_topic = "topic1"
}
{
remote_topic = "fwd/topic2"
local_topic = "topic2"
}
]
quic_keepalive = 120s
quic_idle_timeout = 120s
quic_discon_timeout = 20s
quic_handshake_timeout = 60s
quic_send_idle_timeout = 2s
quic_initial_rtt_ms = 800ms
quic_max_ack_delay_ms = 100ms
quic_multi_stream = false
quic_qos_priority = true
quic_0rtt = true
subscription = [
{
remote_topic = "cmd/topic3"
local_topic = "topic3"
qos = 1
}
{
remote_topic = "cmd/topic4"
local_topic = "topic4"
qos = 2
}
]
sub_properties {
identifier = 1
user_property = {
key1 = value1
key2 = value2
}
}
hybrid_bridging = false
hybrid_servers = ["mqtt-quic://127.1:14567", "mqtt-tcp://127.1:1883"]
max_parallel_processes = 2
max_send_queue_len = 32
max_recv_queue_len = 128
}
bridges.mqtt.cache {
disk_cache_size = 102400
flush_mem_threshold = 100
resend_interval = 5000
}

View File

@ -0,0 +1,58 @@
mqtt {
property_size = 32
max_packet_size = 260MB
max_mqueue_len = 2048
retry_interval = 10s
keepalive_multiplier = 1.25
# Three of below, unsupported now
max_inflight_window = 2048
max_awaiting_rel = 10s
await_rel_timeout = 10s
}
listeners.tcp {
bind = "0.0.0.0:1883"
}
listeners.ws {
bind = "0.0.0.0:8083/mqtt"
}
http_server {
port = 8081
limit_conn = 2
username = admin
password = public
auth_type = basic
jwt {
public.keyfile = "/home/user/Develop/snipplets.dev/projects/nanomq/jwtRS256.key.pub"
}
}
log {
to = [file, console]
level = warn
dir = "/tmp"
file = "nanomq.log"
rotation {
size = 10MB
count = 5
}
}
auth {
allow_anonymous = true
no_match = allow
deny_action = ignore
cache = {
max_size = 32
ttl = 1m
}
# password = {include "/etc/nanomq_pwd.conf"}
# acl = {include "/etc/nanomq_acl.conf"}
}
include "/home/user/Develop/snipplets.dev/projects/nanomq/bridge.conf"

View File

@ -0,0 +1,3 @@
#!/bin/sh
nanomq start --conf $(pwd)/nanomq.conf