Created
November 29, 2018 10:28
-
-
Save riccardomc/44957ea92b1b3d72bb04c9dddd781029 to your computer and use it in GitHub Desktop.
Use AWS SQS as a FIFO queue
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 | |
# | |
# SQS Fifo | |
# | |
#aws sqs create-queue --queue-name q.fifo --attributes FifoQueue=true | |
queue=https://eu-west-1.queue.amazonaws.com/12345678910/q.fifo | |
pop() { | |
message=$(aws sqs receive-message --queue-url $queue --query 'Messages[0]') | |
message_id=$(echo ${message} | jq -r .MessageId) | |
body=$(echo ${message} | jq -r .Body) | |
handle=$(echo ${message} | jq -r .ReceiptHandle) | |
[ "$message_id" == 'null' ] && exit 128 | |
echo $body | |
aws sqs delete-message --queue-url $queue --receipt-handle "$handle" | |
} | |
push() { | |
aws sqs send-message --queue-url $queue \ | |
--message-group-id 1 \ | |
--message-deduplication-id $RANDOM \ | |
--message-body "${1}" | |
} | |
usage() { | |
echo "$0 <pop|push message>" | |
exit 1 | |
} | |
case ${1} in | |
pop) | |
pop | |
;; | |
push) | |
[ -z "${2}" ] && usage | |
push "$2" | |
;; | |
*) | |
usage | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment