Skip to content

Instantly share code, notes, and snippets.

@toff63
Created February 13, 2013 14:38
Show Gist options
  • Select an option

  • Save toff63/4945011 to your computer and use it in GitHub Desktop.

Select an option

Save toff63/4945011 to your computer and use it in GitHub Desktop.

Immutant Web

Immutant provides a session implementation that provides automatic data sharing across nodes in a cluster.

You can have more than 1 web-app deployed in the same container. Each web app having it's own ring handler and context path

Context

Define context in the project.clj:

    (defproject someapp "0.1.0-SNAPSHOT"
      :dependencies [[org.clojure/clojure "1.4.0"]]

      :immutant {:init someapp.core/start
                 :context-path "/foo"})

Sub context in init.clj:

    (web/start "/" ring-handler)
    (web/start "/echo" echo-ring-handler)

Session

Immutant provide session replicated accross cluster node using the ring session middleware.

    (ns my.ns
      (:require [ring.middleware.session :as ring-session]
                [immutant.web :as web]
                [immutant.web.session :as immutant-session]))

    (web/start
     (ring-session/wrap-session
      my-handler
      {:store (immutant-session/servlet-store)}))

Relative path

It doesn't work because you can have several webapp deployed in the same container and not all in root. So you can use an immutant utility:

    (require '[immutant.util :as util])
    (noir.server/load-views (util/app-relative "src/my_project_name/views"))

Static data

Same issue as your application isn't in under root. (immutant.web/wrap-resource app "public")

Immutant Jbos

Jobs in Immutant are simply functions that execute on a recurring schedule. They fire asynchronously, outside of the thread where they are defined, and fire in the same runtime as the rest of the application, so have access to any shared state.

    (ns my.ns
      (:require [immutant.jobs :as jobs]))

    (jobs/schedule "my-job-name" "*/5 * * * * ?" 
                   #(println "I was called!")
                   :singleton false)

Each job scheduled gets its own mbean under the immutant.jobs namespace. This mbean can be used to stop, start, and reschedule the job.

Messaging

Messaging solutions are used to achieve loosely-coupled, asynchronous systems. Uses HornetQ message borker that comes with Jboss 7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment