Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a coercion for SQS MessageAttributeValue #436

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,10 @@ To batch get metric data.

(send-message queue "hello world")

(sqs/send-message :queue-url queue-url
:message-body "hello world"
:message-attributes {"attr" "value"})

(def msgs (receive-message queue))

(delete-message (-> msgs
Expand Down
15 changes: 14 additions & 1 deletion src/amazonica/aws/sqs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@
(:use [amazonica.core :only (kw->str parse-args)]
[clojure.walk :only (stringify-keys)]
[robert.hooke :only (add-hook)])
(:import com.amazonaws.services.sqs.AmazonSQSClient))
(:import com.amazonaws.services.sqs.AmazonSQSClient
[com.amazonaws.services.sqs.model MessageAttributeValue]
[java.nio ByteBuffer]))

(amazonica.core/register-coercions
MessageAttributeValue
(fn [value]
(cond
(string? value) (doto (MessageAttributeValue.) (.withDataType "String") (.withStringValue value))
(number? value) (doto (MessageAttributeValue.) (.withDataType "Number") (.withStringValue (str value)))
(instance? ByteBuffer value) (doto (MessageAttributeValue.) (.withDataType "Binary") (.withBinaryValue value))
:else (throw (ex-info
(format "Values of type %s are not supported for SQS Message Attributes" (class value))
{:value value})))))

(amazonica.core/set-client AmazonSQSClient *ns*)

Expand Down