upgrade to latest AWS SDK, tweak APIs usage to suit.

This commit is contained in:
Chas Emerick 2012-10-02 08:20:06 -04:00
parent 9b782e4817
commit eb2b3524ee
2 changed files with 12 additions and 11 deletions

View file

@ -36,7 +36,7 @@
<dependency> <dependency>
<groupId>com.amazonaws</groupId> <groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId> <artifactId>aws-java-sdk</artifactId>
<version>1.1.5</version> <version>1.3.21.1</version>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -25,16 +25,17 @@
(AmazonSQSClient. (com.amazonaws.auth.BasicAWSCredentials. id secret-key) (AmazonSQSClient. (com.amazonaws.auth.BasicAWSCredentials. id secret-key)
(.withUserAgent client-config "Bandalore - SQS for Clojure")))) (.withUserAgent client-config "Bandalore - SQS for Clojure"))))
(def ^{:private true} visibility-warned? (atom false))
(defn create-queue (defn create-queue
"Creates a queue with the given name, returning the corresponding URL string. "Creates a queue with the given name, returning the corresponding URL string.
Returns successfully if the queue already exists. Returns successfully if the queue already exists."
[^AmazonSQSClient client queue-name & {:as options}]
Specify an optional :visibility keyword arg to set the new queue's default (when (and (:visibility options) (not @visibility-warned?))
visibility timeout in seconds." (println "[WARNING] :visibility option to cemerick.bandalore/create-queue no longer supported;")
[^AmazonSQSClient client queue-name & {:keys [visibility]}] (println "[WARNING] See https://github.com/cemerick/bandalore/issues/3")
(->> (if visibility (reset! visibility-warned? true))
(CreateQueueRequest. queue-name visibility) (->> (CreateQueueRequest. queue-name)
(CreateQueueRequest. queue-name))
(.createQueue client) (.createQueue client)
.getQueueUrl)) .getQueueUrl))
@ -113,9 +114,9 @@
:or {limit 1 :or {limit 1
attributes #{}}}] attributes #{}}}]
(let [req (-> (ReceiveMessageRequest. queue-url) (let [req (-> (ReceiveMessageRequest. queue-url)
(.withMaxNumberOfMessages (-> limit (min 10) (max 1) Integer.)) (.withMaxNumberOfMessages (-> limit (min 10) (max 1) int Integer.))
(.withAttributeNames attributes)) (.withAttributeNames attributes))
req (if visibility (.withVisibilityTimeout req (Integer. visibility)) req)] req (if visibility (.withVisibilityTimeout req (Integer. (int visibility))) req)]
(->> (.receiveMessage client req) (->> (.receiveMessage client req)
.getMessages .getMessages
(map (partial message-map queue-url))))) (map (partial message-map queue-url)))))