thrift-clj

Thrift and Clojure!

View the Project on GitHub xsc/thrift-clj

Using Thrift from Clojure as if it was Clojure!

Apache Thrift is an awesome (and terribly documented) framework for server/client interaction. It let's you define types and service functions, creates whole servers and the respective clients in the blink of an eye. However, there currently is no Thrift IDL to Clojure compiler available.

thrift-clj fills this gap by loading the Java classes generated by the Thrift compiler, making them accessible using plain-and-simple Clojure records and functions.

Use it!

Leiningen

[thrift-clj "0.2.1"]

Clojure

(require '[thrift-clj.core :as thrift])

Types

(thrift/import 
  (:types [test.types Point]))

(def p (Point. 0 0))
(println "Point:" (str "(" (:x p) "," (:y p) ")"))

Clients

(thrift/import
  (:types [test.types Point])
  (:clients [test.service.Painter :as P]))

(with-open [c (thrift/connect! P "localhost:1234" :protocol :json)]
  (P/drawCircle c (Point. 10 10) 5))

Services

(thrift/import
  (:services [test.service.Painter :as P]))

(thrift/defservice painter P
  (drawCircle [{:keys[x y]} radius]
    ...)
  (drawSquare [{:keys[x y]} edge]
    ...)
  ...)

(thrift/serve-and-block!
  (thrift/multi-threaded-server painter 1234 :protocol :json))

Have a look at the Wiki for detailed usage instructions.

Automatic Thrift Compilation

If you want to have your Thrift IDL files compiled to Java automatically, have a look at lein-thriftc!