Skip to content

Commit

Permalink
Convert message headers to/from a clojure map
Browse files Browse the repository at this point in the history
  • Loading branch information
mefesto committed Feb 21, 2011
1 parent 99a34fb commit fb3898e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/com/mefesto/wabbitmq.clj
Expand Up @@ -117,7 +117,9 @@
:correlation-id (.getCorrelationId props)
:delivery-mode (.getDeliveryMode props)
:expiration (.getExpiration props)
:headers (.getHeaders props)
:headers (if-let [hdrs (.getHeaders props)]
(zipmap (map keyword (keys hdrs))
(vals hdrs)))
:message-id (.getMessageId props)
:priority (.getPriority props)
:reply-to (.getReplyTo props)
Expand All @@ -134,7 +136,10 @@
(.setCorrelationId (:correlation-id amap))
(.setDeliveryMode (:delivery-mode amap))
(.setExpiration (:expiration amap))
(.setHeaders (:headers amap))
(.setHeaders (if-let [hdrs (:headers amap)]
(java.util.HashMap.
(zipmap (map name (keys hdrs))
(vals hdrs)))))
(.setMessageId (:message-id amap))
(.setPriority (:priority amap))
(.setReplyTo (:reply-to amap))
Expand Down
7 changes: 7 additions & 0 deletions test/com/mefesto/test_wabbitmq.clj
Expand Up @@ -64,3 +64,10 @@
(is (map? msg))
(is (map? (:envelope msg)))
(is (not (nil? (-> msg :envelope :delivery-tag))))))

(deftest message-headers
(publish "test"
{:headers {"count" 0}}
(.getBytes "hello"))
(let [msg (first (consuming-seq true))]
(is (= (get-in msg [:props :headers :count]) 0))))

0 comments on commit fb3898e

Please sign in to comment.