Skip to content

Commit

Permalink
feat: add support for leafnodes
Browse files Browse the repository at this point in the history
  • Loading branch information
cameri committed Apr 20, 2024
1 parent 09295a7 commit 2c9274a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
18 changes: 16 additions & 2 deletions nats-server/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
"4222/tcp": 4222,
"6222/tcp": 6222,
"8222/tcp": 8222,
"1883/tcp": 1883
"1883/tcp": 1883,
"7422/tcp": 7422
},
"ports_description": {
"4222/tcp": "TCP listening port for NATS clients",
"6222/tcp": "Routing port for clustering",
"8222/tcp": "HTTP management port",
"1883/tcp": "MQTT listening port"
"1883/tcp": "MQTT listening port",
"7422/tcp": "LeafNodes listening port (incoming connections)"
},
"options": {
"jetstream": {
Expand All @@ -39,6 +41,9 @@
"name": "ha-cluster",
"timeout": 2,
"routes": []
},
"leafnodes": {
"remotes": []
}
},
"schema": {
Expand Down Expand Up @@ -82,6 +87,15 @@
"tls_timeout": "int?",
"tls_verify_and_map": "bool?"
},
"leafnodes": {
"allow_incoming_connections": "bool?",
"remotes": [
{
"url": "str",
"credentials": "str?"
}
]
},
"debug": "bool?",
"trace": "bool?",
"logtime": "bool?",
Expand Down
31 changes: 28 additions & 3 deletions nats-server/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CONFIG="/etc/nats/nats-server.conf"
if bashio::config.exists 'jetstream.key'; then
echo " key: $(bashio::config 'jetstream.key')"
fi
echo "}"
echo "}" # jetstream
fi

# MQTT
Expand Down Expand Up @@ -71,7 +71,7 @@ CONFIG="/etc/nats/nats-server.conf"
fi
echo " }" # tls
fi
echo "}"
echo "}" # mqtt
fi

# Clustering
Expand Down Expand Up @@ -139,7 +139,30 @@ CONFIG="/etc/nats/nats-server.conf"
fi
fi

echo "}"
echo "}" # clustering

# LeafNodes
# source: https://docs.nats.io/running-a-nats-service/configuration/leafnodes
echo "leafnodes {"
if bashio::config.exists 'leafnodes.allow_incoming_connections'; then
echo " port = 7422"
fi
if bashio::config.exists 'leafnodes.remotes'; then
echo " remotes = ["
for remote in $(bashio::config 'leafnodes.remotes')
do
REMOTE_URL=$(bashio::jq "$remote" '.url')
REMOTE_CREDENTIALS=$(bashio::jq "$remote" '.credentials')
echo " {"
echo " url: \"$REMOTE_URL\""
if [[ -n "$REMOTE_CREDENTIALS" ]]; then
echo " credentials: \"$REMOTE_CREDENTIALS\""
fi
echo " },"
done
echo " ]"
fi
echo "}" # leafnodes

# Logging
# source: https://docs.nats.io/running-a-nats-service/configuration/logging
Expand All @@ -160,6 +183,8 @@ CONFIG="/etc/nats/nats-server.conf"
fi
} > "$CONFIG"

cat "$CONFIG"

# this if will check if the first argument is a flag
# but only works if all arguments require a hyphenated flag
# -v; -SL; -f arg; etc will work, but not arg1 arg2
Expand Down

0 comments on commit 2c9274a

Please sign in to comment.