Fork me on GitHub

Hi all. I have been spending the last 2 days writing my first clojure code and would just like to get some feedback. All the code does is start a server that listens on 2 routes. On the topics route it will call the message-handler function that gets passed in. I would just like to know if I am on the write track, or if I should change my thinking in some way to be more clojure and less everything else 🙂 thank you


(ns pubsub-watcher.listener
  (:require [org.httpkit.server :as server]
            [compojure.core :refer :all]
            [ring.middleware.defaults :refer :all]
            [pubsub-watcher.log :refer [log]]))

(defn- handle-new-message
  "Executes the message handler with the topic and message on a seperate thread and returns"
  [message-handler topic message]
  (future (message-handler topic message))
  (str "Messeage posted to " topic " topic"))

(defn- create-routes
   (GET "/" [] "All Your Queues Are Belong To Us")
   (POST "/topics/:topic/message" {{topic :topic} :params body :body} (handle-new-message message-handler topic body))))

(defn- create-server
  (wrap-defaults routes site-defaults))

(defn- start-server
  [port server]
  (log (str "** Starting Server on Port " port))
  (server/run-server server {:port port}))

(defn start
  ([port message-handler]
   (let [start-server-on-port (partial start-server port)]
     (-> message-handler
   (start 3333 message-handler)))