forked from SAP-samples/cloud-messaging-handsonsapdev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drain
executable file
·34 lines (26 loc) · 989 Bytes
/
drain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
set -o errexit
source ./localutils.sh
# Drain all messages in a given queue
# - start the webhook endpoint
# - create a webhook subscription to the queue
# - wait for a short while
# - delete webhook subscription
# - (leave the webhook endpoint running)
# MAIN ---------------------------------------------------------------------------
queue=$1
if [[ -z "$queue" ]]; then
echo Specify queue
exit 1
fi
# Names for temporary webhook subscription,
# plus details of webhook app in the cloud.
epoch=$(date "+%s")
webhook_app="webhook"
webhook_url="https://$(cf app "$webhook_app" | awk '/^routes:/ { print $2 }')"
webhook_subscription="drain-$epoch"
log Attaching webhook subscription to app "$webhook_app" for queue "$queue"
./messaging create_webhook_subscription "$webhook_subscription" "$queue" "$webhook_url"
sleep 10
log Cleaning up - deleting webhook subscription "$webhook_subscription"
./messaging delete_webhook_subscription "$webhook_subscription"