This commit is contained in:
Thomas Kruse
2026-02-03 22:29:46 +01:00
commit 8fdf5827e4
156 changed files with 23069 additions and 0 deletions

View File

@ -0,0 +1,7 @@
services:
mosquitto:
image: eclipse-mosquitto
ports:
- "1883:1883"
volumes:
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro

37
01-basics/lab16/lab.txt Normal file
View File

@ -0,0 +1,37 @@
= Last Will and Testament
Nutzen Sie eine Last Will Nachricht mit dem 'mosquitto_pub' Befehl,
um auf dem Topic "clients/demo/status" eine Status Nachricht zu bekommen, sobald der
Publisher Client die Verbindung abbricht.
(Im Lab Ordner ist eine beispielhafte Umsetzung mit will-docker-compose.yaml als Referenz)
Subscriben Sie das Will Topic "clients/+/status"
Beenden Sie den Publisher einmal mit CTRL-C und killen Sie ihn (`kill -SIGKILL`) oder den
zugehörigen TCP Socket (`ss sport =: 1883` und `ss -K sport =:9999`)
Subscriben Sie das Topic "clients/+/status".
$ docker run --rm -it --net host eclipse-mosquitto \
mosquitto_sub --debug -t clients/+/status
Verwenden Sie einen Client mit Last Will Nachricht.
$ docker run --rm -it --net host eclipse-mosquitto \
mosquitto_sub --will-topic clients/room1/status --will-payload offline --will-qos 1 --topic demo
Nutzen Sie folgenden Befehl, um die Sockets der Clients zu finden:
$ docker run --rm -it --net host --cap-add NET_ADMIN alpine:3
# apk -U add iptables iproute2 iproute2-ss
# ss -t sport = :1883
Beenden Sie die TCP Verbindungen mit dem Befehl (Port anpassen):
# ss -t -K sport = :9999

View File

@ -0,0 +1,4 @@
listener 1883
allow_anonymous true
# sys_interval 3

View File

@ -0,0 +1,28 @@
services:
mosquitto:
image: eclipse-mosquitto
ports:
- "1883:1883"
volumes:
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
subscriber:
image: eclipse-mosquitto
network_mode: host
depends_on:
- mosquitto
command: >
sh -c "
mosquitto_sub -t clients/+/status
"
lwt-publisher:
image: eclipse-mosquitto
network_mode: host
depends_on:
- mosquitto
- subscriber
command: >
sh -c "
mosquitto_sub -t sensors/room1/temperature --will-topic clients/room1/status --will-payload offline --will-qos 1
"