Last active
February 29, 2020 23:21
-
-
Save d-mart/daa2215b897775f937d56145883c2e33 to your computer and use it in GitHub Desktop.
easy listener for heroku kafka
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
#!/usr/bin/env bash | |
set -e | |
## Prereqs: | |
## brew install heroku | |
## brew install kafkacat | |
## heroku login -i | |
## Usage exmaple | |
## $ APP=roadie-admin-qa ./kafka-listener.sh gig.events | |
## APP defaults to roadie-api-qa | |
## TOPIC defaults to beta.events | |
# Get config values/creds from heroku by env var name | |
# | |
function get_config_val() { | |
config_key="$1" | |
heroku config:get "$config_key" -a "$APP" | |
} | |
APP="${APP:-roadie-api-qa}" | |
TOPIC="${1:-beta.events}" | |
KAFKA_PREFIX="$(get_config_val KAFKA_PREFIX)" | |
KAFKA_URL="$(get_config_val KAFKA_URL | cut -f 1 -d ',' | sed 's#kafka\+ssl\://##g')" | |
CONSUMER_GROUP="${CONSUMER_GROUP:-cli-consumer-$RANDOM}" | |
kafkacat -C -t "${KAFKA_PREFIX}${TOPIC}" \ | |
-b "$KAFKA_URL" \ | |
-X group.id="$CONSUMER_GROUP" \ | |
-X security.protocol=ssl \ | |
-X ssl.key.location=<(get_config_val KAFKA_CLIENT_CERT_KEY) \ | |
-X ssl.ca.location=<(get_config_val KAFKA_TRUSTED_CERT) \ | |
-X ssl.certificate.location=<(get_config_val KAFKA_CLIENT_CERT) | |
# -o beginning \ |
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
#!/usr/bin/env bash | |
set -e | |
## Prereqs: | |
## brew install heroku | |
## brew install kafkacat | |
## heroku login -i | |
## Usage exmaple | |
## $ APP=roadie-admin-qa ./kafka-writer.sh gig.events | |
## APP defaults to roadie-api-qa | |
if [ -z "$1" ]; then | |
echo "You must specify a topic as the first argument" | |
exit 250 | |
fi | |
TOPIC="$1" | |
APP="${APP:-roadie-api-qa}" | |
function get_config_val() { | |
config_key="$1" | |
heroku config:get "$config_key" -a "$APP" | |
} | |
APP="${APP:-roadie-api-qa}" | |
TOPIC="${1:-beta.events}" | |
KAFKA_PREFIX="$(get_config_val KAFKA_PREFIX)" | |
KAFKA_URL="$(get_config_val KAFKA_URL | cut -f 1 -d ',' | sed 's#kafka\+ssl\://##g')" | |
kafkacat -P -p -1 \ | |
-t "${KAFKA_PREFIX}${TOPIC}" \ | |
-b "$KAFKA_URL" \ | |
-X security.protocol=ssl \ | |
-X ssl.key.location=<(get_config_val KAFKA_CLIENT_CERT_KEY) \ | |
-X ssl.ca.location=<(get_config_val KAFKA_TRUSTED_CERT) \ | |
-X ssl.certificate.location=<(get_config_val KAFKA_CLIENT_CERT) \ | |
-l <(echo "{\"created_at\": \"$(date)\"}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment