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

SQS send-message with message-attributes #435

Open
ctjhoa opened this issue Nov 2, 2020 · 3 comments · May be fixed by #436
Open

SQS send-message with message-attributes #435

ctjhoa opened this issue Nov 2, 2020 · 3 comments · May be fixed by #436

Comments

@ctjhoa
Copy link

ctjhoa commented Nov 2, 2020

Hi,
I try to send an SQS message with a message-attributes.
I notice there is no coercion like SNS ( #179 )
So my code is:

(sqs/send-message {:queue-url queue-url
                   :message-body empty-message-body
                   :message-attributes {(str my-attribute-key) (doto
                                                                 (MessageAttributeValue.)
                                                                   (.withDataType "String")
                                                                   (.withStringValue (str my-attribute-value)))}})

However I've got this exception:

Error setting :message-attributes:
Failed to create an instance of com.amazonaws.services.sqs.model.MessageAttributeValue from
{\"my-attribute-key\" #object[com.amazonaws.services.sqs.model.MessageAttributeValue 0x4762c694 \"{StringValue: my-attribute-value,StringListValues: [],BinaryListValues: [],DataType: String}\"]}
due to java.lang.IllegalArgumentException:
Don't know how to create ISeq from: com.amazonaws.services.sqs.model.MessageAttributeValue.
Make sure the data matches an existing constructor and setters..
Perhaps the value isn't compatible with the setter?

As there is no documentation nor example on this case,
can you tell me if I miss something or if I have a bad send-message usage?
Thanks

@ctjhoa
Copy link
Author

ctjhoa commented Nov 4, 2020

Ok I found my answer on a slack archive
https://clojurians-log.clojureverse.org/aws/2017-01-20

So you should do something like this:

(sqs/send-message {:queue-url a
                   :message-body "hello world!"
                   :message-attributes {:attribute-key
                                                      {:string-value attribute-value
                                                       :data-type "String"
                                                       :string-list-values []
                                                       :binary-list-values []}})

I don't close this issue as I think the interface between SNS & SQS isn't coherent.

(publish :topic-arn "arn:aws:sns:us-east-1:676820690883:my-topic"
         :subject "test"
         :message (str "Todays is " (java.util.Date.))
         :message-attributes {attribute-key attribute-value})

IMO amazonica should allow to do something like this

(sqs/send-message {:queue-url a
                   :message-body "hello world!"
                   :message-attributes {attribute-key attribute-value}})

as Request objects are comparable

https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/sqs/model/SendMessageRequest.html#setMessageAttributes-java.util.Map-
https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/sns/model/PublishRequest.html#setMessageAttributes-java.util.Map-

@mcohen01
Copy link
Owner

mcohen01 commented Nov 6, 2020

Top level service functions take clojure data as arguments, the form of which is governed by the recursive conversion of camel case Java objects to hyphenated clojure data. What do you see as inconsistent here between sqs/send-message and sns/publish? Both are invoked the same way and their arguments coerced to Java objects the same way.

@ctjhoa
Copy link
Author

ctjhoa commented Nov 6, 2020

@mcohen01

Both are invoked the same way and their arguments coerced to Java objects the same way.

They don't coerced the same way. SNS has coercion https://github.com/mcohen01/amazonica/pull/179/files which isn't available in SQS.
This is confusing as only SNS is mentioned in the documentation.
I'll create a PR to add the same coercion mechanism for SQS.

@ctjhoa ctjhoa linked a pull request Nov 6, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants