                :selector (str "JMSCorrelationID='" (.getJMSMessageID message) "'"))))))
 
 (defn respond
-  "Listen for messages on queue sent by the request function and respond with the
-result of applying f to the message. queue can either be the name of the
-queue or a javax.jms.Queue. Accepts the same options as listen."
-  [queue f & {:keys [decode?] :or {decode? true} :as opts}]
-  {:pre [(queue? queue)]}
+  "Listen for messages on queue sent by the request function and
+   respond with the result of applying f to the message. queue can
+   either be the name of the queue or a javax.jms.Queue. Accepts the
+   same options as listen."
+  [queue f & {:keys [decode?] :or {decode?
+   true} :as opts}] {:pre [(queue? queue)]}
   (letfn [(respond* [^javax.jms.Message msg]
             (publish (.getJMSDestination msg)
                      (f (codecs/decode-if decode? msg))


(defn request
  "Send a message to queue and return a delay that will retrieve the response.
Implements the request-response pattern, and is used in conjunction with respond.
queue can either be the name of the queue or a javax.jms.Queue.
In addition to the same options as publish, it also accepts [default]:
   :timeout  time in ms for the delayed receive to wait once it it is
             dereferenced, after which nil is returned [10000]"
  [queue message & {:as opts}]
  {:pre [(queue? queue)]}
  (let [^javax.jms.Message message (mapply publish queue message

        (codecs/decode-if decode? encoded)))))

(defn message-seq
  "A lazy sequence of messages received from a destination. Accepts
   same options as receive"
  [dest & opts]
  (lazy-seq (cons (apply receive dest opts) (message-seq dest))))

(defn listen
  "The handler function, f, will receive each message sent to dest.
   dest can either be the name of the destination or a
   javax.jms.Destination.

   The following options are supported [default]:
     :concurrency  the number of threads handling messages [1]
     :selector     A JMS (SQL 92) expression matching message properties
     :decode?      if true, the decoded message body is passed to f. Otherwise, the
                   javax.jms.Message object is passed [true]
     :host         the remote host to connect to (default is to connect in-vm) [nil]
     :port         the remote port to connect to (requires :host to be set) [nil,
                   or 5445 if :host is set]
     :username     the username to use to auth the connection (requires :password
                   to be set) [nil]
     :password     the password to use to auth the connection (requires :username
                   to be set) [nil]"
  [dest f & {:keys [concurrency selector decode?] :or {concurrency 1 decode? true} :as opts}]
  (let [connection (.createXAConnection (connection-factory opts)
                                        (:username opts)
