Last active
August 29, 2015 14:13
-
-
Save gknapp/6c10695c8a8329f13378 to your computer and use it in GitHub Desktop.
ack / nack rabbitmq msg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; ACK/NACK a rabbitmq message. | |
;; Construct a frame as per the STOMP 1.1 spec: | |
;; https://stomp.github.io/stomp-specification-1.1.html#ACK | |
;; | |
;; Used for reference: | |
;; https://github.com/easternbloc/node-stomp-client/blob/master/lib/client.js | |
(ns cljs-node-stomp.queue | |
(:require [cljs.nodejs :as node])) | |
;; Require `stomp-client frame` for ACK / NACK | |
(def StompFrame (.-StompFrame (node/require "stomp-client/lib/frame"))) | |
;; if you're wondering where msg-id and sub-id comes from ... in my | |
;; subscribe function (not included in this gist) I push the message | |
;; headers into the msg meta data | |
(defn receipt | |
([client queue cmd msg] | |
(receipt client queue cmd msg {})) | |
([client queue cmd msg hdrs] | |
(let [msg-id (-> msg meta :message-id) | |
sub-id (-> msg meta :id) | |
headers {:destination queue | |
:message-id msg-id | |
:id sub-id} | |
headers (merge hdrs headers) | |
args {:command cmd :headers headers :body ""} | |
frame (StompFrame. (clj->js args))] | |
(.send frame (.-stream client))))) | |
;; ## ack | |
;; Acknowledge message. | |
;; does not (yet) support message transactions | |
(defn ack | |
[client queue msg] | |
(receipt client queue "ACK" msg)) | |
;; ## nack | |
;; Reject message. | |
;; does not (yet) support message transactions | |
(defn nack | |
([client queue msg] | |
(nack client queue msg true)) | |
([client queue msg requeue] | |
(receipt client queue "NACK" msg requeue))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment