Skip to content

Instantly share code, notes, and snippets.



Last active Dec 20, 2015
What would you like to do?
setting pattern-matched jboss/hornetq `address-settings` programmatically, using immutant
(ns immutant.messaging.util
(:import org.hornetq.core.settings.impl.AddressFullMessagePolicy
(:require immutant.registry
[immutant.messaging :as msg]
[clojure.string :as str]))
(defn- set-bean-property
[bean pname value]
(let [setter (as-> (name pname) %
(str/split % #"-")
(map str/capitalize %)
(apply str ".set" %)
(symbol %))]
((eval `#(~setter % %2)) bean value)))
(defn- address-settings
(-> (immutant.registry/get "jboss.messaging.default")
(.getMatch match-string)))
([match-string new-settings]
(-> (immutant.registry/get "jboss.messaging.default")
(.addMatch match-string new-settings))))
(def ^:private address-settings-coercions
(fn [m [k v]]
(-> (assoc m k v)
(assoc (symbol (name k)) v)
(assoc (name k) v)))
{:dead-letter-address #(SimpleString. %)
:expiry-address #(SimpleString. %)
:address-full-message-policy #(case (name %)
"block" AddressFullMessagePolicy/BLOCK
"drop" AddressFullMessagePolicy/DROP
"page" AddressFullMessagePolicy/PAGE)}))
(defn start+
"Same as `immutant.messaging/start`, but allows you to set queue parameters
corresponding to those available via the `address-settings` elements in
various hornetq and jboss XML configuration files. See
for more info.
e.g. (start \"\"
:dead-letter-address \"WTF!\"
:address-full-message-policy :block
:redelivery-delay 2000)"
[queue-name & {:as opts}]
(let [global-opts (dissoc opts :durable :selector)
queue-local-opts (select-keys opts [:durable :selector])
ret (apply msg/start queue-name (flatten (seq queue-local-opts)))]
(when (seq global-opts)
;; TODO should properly log using whatever immutant/jboss likes
(println "Setting <address-settings> for queue" queue-name ": " global-opts)
;; assuming here that queue-name is the shortened style immutant
;; recommends; need to add the jboss/jms prefix so lookups happen properly
(address-settings (str "jms.queue." queue-name)
(fn [s [k v]]
(doto s
k ((address-settings-coercions k identity) v))))

This comment has been minimized.

Copy link

@hiredman hiredman commented Jul 30, 2013

using % with as-> is cute


This comment has been minimized.

Copy link
Owner Author

@cemerick cemerick commented Aug 1, 2013

Might as well, right? :-) Would get a little nasty if there was a fn literal in there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.