TheClimateCorporation / squeedo

clojure core.async based amazon SQS message processing
Apache License 2.0
62 stars 28 forks source link

Binary message attributes #30

Closed vincentjames501 closed 7 years ago

vincentjames501 commented 7 years ago

Haven't looked into this much, but message attributes should check what the data type of the MessageAttributeValue is and call the correct getter.

(defn- clojurify-message-attributes [^Message msg]
  (let [javafied-message-attributes (.getMessageAttributes msg)]
    (->> javafied-message-attributes
         (map (fn [[k ^MessageAttributeValue mav]] [(keyword k) (.getStringValue mav)]))
         (into {}))))

Untested but possible solution instead of (.getStringValue mav):

(case (.getDataType mav)
  "String" (.getStringValue mav)
  "Number" (try
             (BigDecimal. (.getStringValue mav))
             (catch NumberFormatException e
               {:error e :original-value (.getStringValue mav)}))
  "Binary" (.getBinaryValue mav))
mtkp commented 7 years ago

thanks for catching this @vincentjames501. your possible solution looks good to me, though i think i'd be inclined to handle Number and String the same way (just use .getStringValue for both). happy to accept a PR, otherwise i'll look into this when i have time.

mtkp commented 7 years ago

@vincentjames501 i think i've got this covered in #35 (see line 180 in sqs.clj)