Created
May 26, 2012 06:09
-
-
Save jhulten/2792517 to your computer and use it in GitHub Desktop.
clojure udp aleph example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns statsd-clj.server | |
(:use [aleph.udp] | |
[gloss core io] | |
[lamina core api]) | |
(:require [statsd-clj.config :as config] | |
[statsd-clj.metrics :as metrics] | |
[clojure.tools.logging :as log])) | |
(def socket-server (agent nil)) | |
(defn create-server | |
[host port] | |
(udp-socket | |
{:frame (string :utf-8 :as-str true) | |
:port port | |
:address host})) | |
(defn start | |
[host port] | |
(log/infof "statsd udp server [%s:%s]: starting" host port) | |
(send socket-server #(or % (create-server host port))) | |
(receive-all @socket-server #(metrics/capture-metric (:message %))) | |
(log/info "statsd udp server: started")) | |
(defn stop | |
[] | |
(log/info "statsd udp server: stopping") | |
(send socket-server close) | |
(shutdown-agents) | |
(log/info "statsd udp server stopped")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment