Adding a little context : I want to build a stateful load-balancer to send to multiple riemann servers.
Here's what I came up with:
(defn forward-balanced-stateful
"Forwards events to a pool of riemann tcp clients.
The client is chosen using the event's fields, hence the stateful suffix."
[clients fields]
(let [get-relay-idx (fn [event] (mod (hash (select-keys event fields)) (count clients)))]
(by-builder [idx get-relay-idx] (batch 100 10 (forward (get clients idx))))))
And here's how I'm using it in a stream:
(let [forward_balanced_safe-tcp_clients [(tcp-client :host "remote-riemann-1" :port 5555)(tcp-client :host "remote-riemann-2" :port 5555)]
(streams (forward-balanced-stateful forward_balanced_safe-tcp_clients [:host :service])))))))
Does that seem correct to you?