Files
sq/scripts/grpc.sh
2026-02-27 12:15:43 +01:00

46 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Helper script for testing SQ gRPC endpoints with grpcurl.
# Usage: ./scripts/grpc.sh <command> [args...]
#
# Commands:
# status [addr] - Get node status
# publish <topic> <msg> - Publish a message
# subscribe <topic> - Subscribe to a topic
# topics - List topics
set -euo pipefail
ADDR="${SQ_ADDR:-127.0.0.1:6060}"
case "${1:-help}" in
status)
addr="${2:-$ADDR}"
grpcurl -plaintext "$addr" sq.v1.StatusService/Status
;;
publish)
topic="${2:?topic required}"
msg="${3:?message required}"
grpcurl -plaintext -d "{\"topic\": \"$topic\", \"messages\": [{\"value\": \"$(echo -n "$msg" | base64)\"}]}" \
"$ADDR" sq.v1.DataPlaneService/Publish
;;
subscribe)
topic="${2:?topic required}"
grpcurl -plaintext -d "{\"topic\": \"$topic\", \"partition\": 0}" \
"$ADDR" sq.v1.DataPlaneService/Subscribe
;;
topics)
grpcurl -plaintext "$ADDR" sq.v1.ControlPlaneService/ListTopics
;;
help|*)
echo "Usage: $0 <command> [args...]"
echo ""
echo "Commands:"
echo " status [addr] - Get node status"
echo " publish <topic> <msg> - Publish a message"
echo " subscribe <topic> - Subscribe to a topic"
echo " topics - List topics"
echo ""
echo "Environment: SQ_ADDR (default: 127.0.0.1:6060)"
;;
esac