Skip to content

Commit

Permalink
[#174] Message queue: add qname to arg map passed to queue handler (@…
Browse files Browse the repository at this point in the history
…dparis)

Pass the qname value from the handle1 context as part of the argument
map passed to the queue handler function.
  • Loading branch information
dparis authored and ptaoussanis committed Jun 22, 2016
1 parent 9db1614 commit 67e2514
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/taoensso/carmine/message_queue.clj
Expand Up @@ -203,7 +203,8 @@
"Error handling %s queue message:\n%s" qname poll-reply))

{:keys [status throwable backoff-ms]}
(let [result (try (handler {:mid mid :message mcontent :attempt attempt})
(let [result (try (handler {:qname qname :mid mid
:message mcontent :attempt attempt})
(catch Throwable t {:status :error :throwable t}))]
(when (map? result) result))]

Expand Down Expand Up @@ -295,7 +296,7 @@
(defn worker
"Returns a threaded worker to poll for and handle messages `enqueue`'d to
named queue. Options:
:handler - (fn [{:keys [mid message attempt]}]) that throws an ex
:handler - (fn [{:keys [qname mid message attempt]}]) that throws an ex
or returns {:status <#{:success :error :retry}>
:throwable <Throwable>
:backoff-ms <retry-or-dedupe-backoff-ms}.
Expand Down
6 changes: 3 additions & 3 deletions test/taoensso/carmine/tests/message_queue.clj
Expand Up @@ -50,7 +50,7 @@

;; Handler will *not* run against eoq-backoff/nil reply:
(is (= nil (mq/handle1 conn-opts tq nil (wcar* (dequeue* tq)))))
(is (= {:mid "mid1" :message :msg1, :attempt 1}
(is (= {:qname :carmine-test-queue :mid "mid1" :message :msg1, :attempt 1}
(let [p (promise)]
(mq/handle1 conn-opts tq #(do (deliver p %) {:status :success})
(wcar* (dequeue* tq)))
Expand All @@ -76,7 +76,7 @@
(deftest tests-4 ; Handling: retry with backoff
(is (= "mid1" (do (clear-tq) (wcar* (mq/enqueue tq :msg1 :mid1)))))
(is (= "eoq-backoff" (wcar* (dequeue* tq))))
(is (= {:mid "mid1" :message :msg1, :attempt 1}
(is (= {:qname :carmine-test-queue :mid "mid1" :message :msg1, :attempt 1}
(let [p (promise)]
(mq/handle1 conn-opts tq
#(do (deliver p %) {:status :retry :backoff-ms 3000})
Expand All @@ -92,7 +92,7 @@
(deftest tests-5 ; Handling: success with backoff (dedupe)
(is (= "mid1" (do (clear-tq) (wcar* (mq/enqueue tq :msg1 :mid1)))))
(is (= "eoq-backoff" (wcar* (dequeue* tq))))
(is (= {:mid "mid1" :message :msg1, :attempt 1}
(is (= {:qname :carmine-test-queue :mid "mid1" :message :msg1, :attempt 1}
(let [p (promise)]
(mq/handle1 conn-opts tq
#(do (deliver p %) {:status :success :backoff-ms 3000})
Expand Down

0 comments on commit 67e2514

Please sign in to comment.