Files
spring-messaging-demo/share-groups/scripts/broker-up.sh
T
Claude 5db56e70a0 Add share-groups module: Kafka 4.3.1 share groups with Spring for Apache Kafka 4.1.1
Six consumers on two partitions under a consumer group, a share group with the default
share.acquire.mode and a share group with record_limit; the three acknowledgement types and a
record that is released until Kafka stops redelivering it; a new share group starting at latest;
the ordering a share group gives up; and Spring Kafka's share containers in implicit and manual
acknowledgement modes. Tests run against a real broker (scripts/broker-up.sh) and write output/.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Lm655hdgDo5xsSLNomgdsy
2026-10-13 02:43:36 +00:00

41 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Downloads Apache Kafka 4.3.1 (checksum-verified), formats a single-node KRaft cluster and starts it.
# Usage: scripts/broker-up.sh [client-port] (default 9092; the controller uses client-port + 1)
set -euo pipefail
VERSION=4.3.1
PORT="${1:-9092}"
CTRL=$((PORT + 1))
HOME_DIR="${KAFKA_DIR:-$(cd "$(dirname "$0")/.." && pwd)/.kafka}"
TGZ="kafka_2.13-${VERSION}.tgz"
mkdir -p "$HOME_DIR" && cd "$HOME_DIR"
if [ ! -d "kafka_2.13-${VERSION}" ]; then
curl -fsSL -o "$TGZ" "https://downloads.apache.org/kafka/${VERSION}/${TGZ}"
curl -fsSL -o "${TGZ}.sha512" "https://downloads.apache.org/kafka/${VERSION}/${TGZ}.sha512"
# The .sha512 file is "name: HEX HEX HEX ..." in groups, so compare after stripping spaces and the name.
expected="$(sed 's/^[^:]*: *//' "${TGZ}.sha512" | tr -d ' \n' | tr 'A-F' 'a-f')"
actual="$(sha512sum "$TGZ" | cut -d' ' -f1)"
[ "$expected" = "$actual" ] || { echo "checksum mismatch for $TGZ" >&2; exit 1; }
tar -xzf "$TGZ"
fi
cd "kafka_2.13-${VERSION}"
sed -i "s#^listeners=.*#listeners=PLAINTEXT://:${PORT},CONTROLLER://:${CTRL}#" config/server.properties
sed -i "s#^advertised.listeners=.*#advertised.listeners=PLAINTEXT://localhost:${PORT}#" config/server.properties
sed -i "s#^controller.quorum.bootstrap.servers=.*#controller.quorum.bootstrap.servers=localhost:${CTRL}#" config/server.properties
sed -i "s#^log.dirs=.*#log.dirs=${HOME_DIR}/data-${PORT}#" config/server.properties
if [ ! -d "${HOME_DIR}/data-${PORT}" ]; then
bin/kafka-storage.sh format --standalone -t "$(bin/kafka-storage.sh random-uuid | tail -1)" -c config/server.properties
fi
export KAFKA_HEAP_OPTS="${KAFKA_HEAP_OPTS:--Xmx512m -Xms512m}"
setsid nohup bin/kafka-server-start.sh config/server.properties > "${HOME_DIR}/broker-${PORT}.log" 2>&1 < /dev/null &
for _ in $(seq 1 60); do
bin/kafka-topics.sh --bootstrap-server "localhost:${PORT}" --list > /dev/null 2>&1 && break
sleep 2
done
echo "broker up on localhost:${PORT}; share.version feature:"
bin/kafka-features.sh --bootstrap-server "localhost:${PORT}" describe | grep share.version