share-lt/docs/docker/create_nats_stream.sh

47 lines
970 B
Bash
Raw Normal View History

#!/usr/bin/env bash
# This script creates a NATS stream using the nats CLI tool.
# It reads the stream name, password, and subject from an .env file.
ENV_FILE=".env"
if [ ! -f "$ENV_FILE" ]; then
echo ".env file not found at $ENV_FILE"
exit 1
fi
. "$ENV_FILE"
if [ -z "$NATS_STREAM" ]; then
echo "NATS_STREAM is not set in .env file"
exit 1
fi
if [ -z "$NATS_PASSWORD" ]; then
echo "NATS_PASSWORD is not set in .env file"
exit 1
fi
if [ -z "$NATS_SUBJECT" ]; then
echo "NATS_SUBJECT is not set in .env file"
exit 1
fi
nats \
stream add "$NATS_STREAM" \
--user ruser --password $NATS_PASSWORD \
--subjects "$NATS_SUBJECT" \
--storage file \
--dupe-window="2m" \
--replicas=1 \
--max-msgs-per-subject=-1 \
--no-allow-rollup \
--no-deny-delete \
--no-deny-purge \
--discard=old \
--max-msgs=-1 \
--max-bytes=-1 \
--max-msg-size=-1 \
--max-age=1h \
--retention limits