Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Consul Blocking query example
#!/bin/bash -e
CONSUL_ADDR=${CONSUL_ADDR="http://consul.service.consul:8500"}
CONSUL_ENDPOINT=${CONSUL_ENDPOINT="/v1/catalog/services"}
while true; do
INDEX_FILE="$(mktemp -t consul_index_)"
CONSUL_INDEX=$(
curl -isL \
-H 'X-Consul-Index: 1' \
"${CONSUL_ADDR}${CONSUL_ENDPOINT}?index=$CONSUL_INDEX&wait=10s" | \
tee "$INDEX_FILE" | \
grep -i X-Consul-Index | \
sed -e 's/^.*: *//' | \
tr -d '\015')
echo "X-Consul-Index: ${CONSUL_INDEX}"
cat $INDEX_FILE | tr -d '\015' | sed -e '1,/^$/d' | jq '.'
rm -f "$INDEX_FILE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment