Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make it possible to set heartbeat interval and connection timeout

  • Loading branch information...
commit a9cd2bd7081636e6e0b9a018ffb8e59fa1cad3aa 1 parent b52a0ec
@michaelklishin michaelklishin authored
View
1  .travis.yml
@@ -1 +1,2 @@
language: clojure
+before_script: ./bin/ci/before_script.sh
View
15 bin/ci/before_script.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+# guest:guest has full access to /
+
+sudo rabbitmqctl add_vhost /
+sudo rabbitmqctl add_user guest guest
+sudo rabbitmqctl set_permissions -p / guest ".*" ".*" ".*"
+
+
+# langohr:langohr.password has full access to / and langohr_testbed
+
+sudo rabbitmqctl add_vhost langohr_testbed
+sudo rabbitmqctl add_user langohr "langohr.password"
+sudo rabbitmqctl set_permissions -p / langohr ".*" ".*" ".*"
+sudo rabbitmqctl set_permissions -p langohr_testbed langohr ".*" ".*" ".*"
View
17 src/langohr/core.clj
@@ -105,10 +105,15 @@
(defn- ^ConnectionFactory create-connection-factory
"Creates connection factory from given attributes"
[config]
- (let [{:keys [host port username password vhost]} (get-config config)]
+ (let [{:keys [host port username password vhost requested-heartbeat connection-timeout] :or {
+ requested-heartbeat ConnectionFactory/DEFAULT_HEARTBEAT
+ connection-timeout 10
+ } } (get-config config)]
(doto (ConnectionFactory.)
- (.setUsername username)
- (.setPassword password)
- (.setVirtualHost vhost)
- (.setHost host)
- (.setPort port))))
+ (.setUsername username)
+ (.setPassword password)
+ (.setVirtualHost vhost)
+ (.setHost host)
+ (.setPort port)
+ (.setRequestedHeartbeat requested-heartbeat)
+ (.setConnectionTimeout connection-timeout))))
View
11 test/langohr/test/core.clj
@@ -10,6 +10,17 @@
(is (instance? com.rabbitmq.client.Connection conn))
(is (open? conn))))
+(deftest t-connection-with-overriden-parameters
+ ;; see ./bin/ci/before_script.sh
+ (let [conn (connect {
+ :host "127.0.0.1" :port 5672
+ :vhost "langohr_testbed" :username "langohr" :password "langohr.password"
+ :requested-heartbeat 3 :connection-timeout 5 })]
+ (is (open? conn))
+ (is (= "127.0.0.1" (-> conn .getAddress .getHostAddress)))
+ (is (= 5672 (.getPort conn)))
+ (is (= 3 (.getHeartbeat conn)))))
+
(deftest t-connection-failure-due-to-misconfigured-port
(is (thrown? java.net.ConnectException (connect { :host "127.0.0.1" :port 2887 }))))
Please sign in to comment.
Something went wrong with that request. Please try again.