Files

82 lines
2.2 KiB
Markdown

# Message Bus Inbox Processor (19.07.2026)
## Das Problem
`mesh-pull-from-a` auf B holt Nachrichten von A's outbox in B's inbox. Aber NIEMAND liest B's inbox. Nachrichten bleiben ewig liegen.
## Die Lösung: `mesh-process-inbox.sh`
Auf **Agent B** einrichten:
```bash
#!/bin/bash
# /usr/local/bin/mesh-process-inbox.sh
INBOX=/root/.hermes/msg_bus/inbox
SENT=/root/.hermes/msg_bus/sent
LOG=/root/.hermes/msg_bus/processed.log
shopt -s nullglob
for f in "$INBOX"/*.json; do
ts=$(date -Iseconds)
topic=$(python3 -c "import json; print(json.load(open('$f')).get('topic','?'))" 2>/dev/null)
echo "[$ts] PROCESSED: $topic" >> "$LOG"
/usr/local/bin/mesh-send-to-a "msg-received" "$topic" 2>/dev/null
mv "$f" "$SENT"/
done
```
**System-Cron auf B (root crontab):**
```
* * * * * /usr/local/bin/mesh-process-inbox.sh
* * * * * sleep 30; /usr/local/bin/mesh-process-inbox.sh
```
## Bidirektionaler Flow
```
A ──mesh-send-to-b──▶ B/inbox (sofort, scp)
B/inbox ──processor-cron──▶ B/outbox (alle 30s, via mesh-send-to-a)
B/outbox ──mesh-pull-from-b──▶ A/inbox (alle 30s, scp)
```
## Heredoc-Pitfall beim Erstellen via SSH
Wenn du das Script von Agent A aus per SSH erstellst, verursachen doppelte Anführungszeichen und `$`-Variablen im Heredoc Syntaxfehler:
```bash
# FALSCH — Anführungszeichen falsch escaped:
ssh B 'sudo tee /script.sh << EOF
for f in "$INBOX"/*.json 2>/dev/null; do
EOF'
# RICHTIG — mit quoted delimiter und korrektem Escaping:
ssh B 'sudo tee /script.sh > /dev/null << '\''ENDOFSCRIPT'\''
#!/bin/bash
shopt -s nullglob
for f in "$INBOX"/*.json; do
topic=$(python3 -c "import json; print(json.load(open('"'"'$f'"'"')).get('"'"'topic'"'"'))" 2>/dev/null)
...
done
ENDOFSCRIPT'
```
**Alternativ:** Script lokal auf A schreiben, dann per `scp` nach B pushen. Umgeht das gesamte Escaping-Problem.
## Verifikation
```bash
# 1. Test-Nachricht senden
mesh-send-to-b "test" "ping"
# 2. 35s warten (Cron-Intervall)
sleep 35
# 3. B's Inbox prüfen — muss LEER sein
ssh B 'sudo ls /root/.hermes/msg_bus/inbox/'
# 4. B's Log prüfen
ssh B 'sudo cat /root/.hermes/msg_bus/processed.log'
# 5. A's Inbox prüfen — Bestätigung muss angekommen sein
ls /root/.hermes/msg_bus/inbox/
```