The namespace tcp-driver.io.pool
provides all the functions required to create a keyed
connection pool. Each key is a host address of type {:host <host> :port <port>}
and
creates a sub pool of TCP connections.
The default IPool
implementation uses the apache commons object pool,
see https://commons.apache.org/proper/commons-pool/
(require '[tcp-driver.io.pool :as tcp-pool])
(require '[tcp-driver.io.conn :as tcp-conn])
(def pool (tcp-pool/create-tcp-pool {}))
(def host (tcp-conn/host-address "localhost" 8001))
(def timeout-ms 1000)
;;manual borrow and return
(let [conn (tcp-pool/borrow pool host timeout-ms)]
;;do something with conn
(tcp-pool/return pool host))
;; or convenience function
(tcp-pool/try-conn pool host timeout-ms
(fn [conn]
;;do something with conn
))
clojure (tcp-pool/create-tcp-pool conf)
Conf values are:
Key | Value/Description |
:max-idle-per-key | Max connections idle for a pool to a particular server, default is 2 |
:min-idle-per-key | Minimum connections idle for a pool to a particular server, default is 0 |
:max-total | The maximum number of connections to open for all servers, default is 100 |
:max-total-per-key | Same as :max-total but per key, default is 100 |
:min-idle-per-key | Maximum idle connections per key, default is 0 |
:close-pool-jvm-shutdown | If set to true, the pool will be closed for all keys and connections on JVM shutdown |
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close