JVM Rocks

java, groovy, grails, gradle, clojure.

Vertx: Create Vertx Instance(clojure)

Setup project as described in previous post

open a terminal window, run lein repl

1
lein repl

require vertx.embed and then set vertx instance atom

1
2
(require '[vertx.embed :as embed])
(embed/set-vertx! (embed/vertx))

now you can start a server, for example to start a http server do the following

import the http namespace

1
  (require '[vertx.http :as http]))

declare a request handler

1
2
3
4
  (defn req-handler [req]
  (-> (http/server-response req)
      (http/add-header "Content-Type" "text/html; charset=UTF-8")
      (http/end "<html><body><h4>Vertx Rocks!</h4></body></html>")))

start server using the handler and assign it to a variable server

1
2
3
(def server (-> (http/server)
    (http/on-request req-handler)
    (http/listen 8080 "localhost")))