Created
September 18, 2018 14:39
-
-
Save marceloalmeida/bc5c09d6b9927538ad7ddca4aaf6900f to your computer and use it in GitHub Desktop.
Consul Blocking query example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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