Skip to content

Instantly share code, notes, and snippets.

@cap10morgan
Created July 20, 2015 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cap10morgan/c022fda990b870005434 to your computer and use it in GitHub Desktop.
Save cap10morgan/c022fda990b870005434 to your computer and use it in GitHub Desktop.
lazy-seq connect-to-broker
(defn connect-to-broker
([config] (connect-to-broker config 5))
([config max-tries]
(first (drop-while nil? (connect-to-broker config max-tries 1))))
([config max-tries attempt]
(if (<= attempt max-tries)
(try
[(rmq/connect config)]
(catch Throwable t
(log/warn "RabbitMQ not available:" (.getMessage t) "attempt:" attempt)
(lazy-seq
(Thread/sleep (* attempt 1000))
(connect-to-broker config max-tries (inc attempt)))))
nil)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment