Skip to content

Instantly share code, notes, and snippets.

@marceloalmeida
Created September 18, 2018 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marceloalmeida/bc5c09d6b9927538ad7ddca4aaf6900f to your computer and use it in GitHub Desktop.
Save marceloalmeida/bc5c09d6b9927538ad7ddca4aaf6900f to your computer and use it in GitHub Desktop.
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