Fixes for #15 indirectly, without updating the conn-alive? interface. (Perhaps work-around?)
Changes include
Call a "carmine:error" message handler if available with the exception and throw it as normal. Can be used by consumers to create handlers for connection failures
Added keep-alive calls for listeners to call ping, expecting this to be called to prevent idle timeouts from client with a property ping-ms in the conn spec
With the above changes, it is possible to handle errors from listeners as they come. Auto-resubscribe may not be the right thing for carmine library to handle, it should be consumers. Ideally raising alerts for devops to pick up on, rather than current silent failures.
Testing
Tested with redis 4.0.6
(require '[taoensso.carmine :as car])
(require '[taoensso.carmine.connections :as conns])
(def redis-conn-spec {:pool {:test-while-idle? true}
:spec {:host "<<yourhost>>" :port 6379 :password "<<yourpassword>>"}})
(defn wrap-listener-fn [listener-fn]
(fn [[t channel msg]]
(println (System/currentTimeMillis) "channel matched - " t channel msg)
(listener-fn msg)))
(defn err-handler [e]
(println "Exception in listener" e)
;; TODO Handle rebinding based on type of e - eg: retry n attempts and become a fatal exception for an alert system to pick up
;; could be timeout, remote disconnect, remote reconnect
)
(defn subscribe
"Subscribes and returns a listener handle. To unsubscribe, keep a reference to the return val"
[channel listener-fn]
(let [channel-name (name channel)
;; spec can have socket read-timeout-ms as something greater than ping-ms to fail almost immediately when socket wait exceeds it
listener (car/with-new-pubsub-listener (:spec redis-conn-spec)
{
channel-name (wrap-listener-fn listener-fn)
"carmine:listener:fail" (wrap-listener-fn err-handler)}
(car/subscribe channel-name))]
listener))
(def a1 (subscribe :test1 println))
(def a2 (subscribe :test2 println))
Connection timeout after no updates on channel for n=10 minutes
Fixes for #15 indirectly, without updating the conn-alive? interface. (Perhaps work-around?)
Changes include
With the above changes, it is possible to handle errors from listeners as they come. Auto-resubscribe may not be the right thing for carmine library to handle, it should be consumers. Ideally raising alerts for devops to pick up on, rather than current silent failures.
Testing
Tested with redis 4.0.6
Connection timeout after no updates on channel for n=10 minutes
Connection reset by remote disconnect