Using Transit with Immutant 2

Out of the box, Immutant 2 has support for several data serialization strategies for use with messaging and caching, namely: EDN, Fressian, JSON, and none (which falls back to Java serialization). But what if you want to use another strategy? Luckily, this isn't a closed set - Immutant allows us to add new strategies. We took advantage of that and have created a separate project that brings Transit support to Immutant - immutant-transit.

What is Transit?

From the Transit format page:

Transit is a format and set of libraries for conveying values between applications written in different programming languages.

It's similar in purpose to EDN, but leverages the speed of the optimized JSON readers that most platforms provide.

What does immutant-transit offer over using Transit directly?

immutant-transit provides an Immutant codec for Transit that allows for transparent encoding and decoding of Transit data when using Immutant's messaging and caching functionality. Without it, you would need to set up the encode/decode logic yourself.

Usage

Note: immutant-transit won't work with Immutant 2.0.0-alpha1 - you'll need to use an incremental build (#298 or newer).

First, we need to add org.immutant/immutant-transit to our application's dependencies:

  :dependencies [[org.clojure/clojure "1.6.0"]
                 [org.immutant/immutant "2.x.incremental.298"]
                 [org.immutant/immutant-transit "0.2.2"]]

If you don't have com.cognitect/transit-clj in your dependencies, immutant-transit will transitively bring in version 0.8.259. We've tested against 0.8.255 and 0.8.259, so if you're running another version and are seeing issues, let us know.

Now, we need to register the Transit codec with Immutant:

  (ns your.app
    (:require [immutant.codecs.transit :as it]))

  (it/register-transit-codec)

This will register a vanilla JSON Transit codec that encodes to a byte[] under the name :transit with the content-type application/transit+json (Immutant uses the content-type to identify the encoding for messages sent via HornetQ).

To use the codec, provide it as the :encoding option wherever an encoding is used:

  (immutant.messaging/publish some-queue {:a :message} :encoding :transit)

  (def transit-cache (immutant.caching/with-codec some-cache :transit))
  (immutant.caching/compare-and-swap! transit-cache a-key a-function)

If you need to change the underlying format that Transit uses, or need to provide custom read/write handlers, you can pass them as options to register-transit-codec:

  (it/register-transit-codec
    :type :json-verbose
    :read-handlers my-read-handlers
    :write-handlers my-write-handlers)

The content-type will automatically be generated based on the :type, and will be of the form application/transit+<:type>.

You can also override the name and content-type:

  (it/register-transit-codec
    :name :transit-with-my-handlers
    :content-type "application/transit+json+my-stuff"
    :read-handlers my-read-handlers
    :write-handlers my-write-handlers)

For more examples, see the example project.

Why is this a separate project from Immutant?

Transit's format and implementation are young, and are still in flux. We're currently developing this as a separate project so we can make releases independent of Immutant proper that track changes to Transit. Once Transit matures a bit, we'll likely roll this in to Immutant itself.

If you are interested in adding a codec of your own, take a look at the immutant-transit source and at the immutant.codecs namespace to see how it's done.

Get In Touch

If you have any questions, issues, or other feedback about mmutant-transit, you can always find us on #immutant on freenode or our mailing lists.

Immutant 2 (The Deuce) Alpha Released

We're as excited as this little girl to announce our first alpha release of The Deuce, Immutant 2.0.0-alpha1.

This represents a significant milestone for us, as we've completely removed the app server from Immutant. It's just jars now. We've put a lot of thought into the API and performed enough integration testing to feel confident putting an alpha out at this time.

Big, special thanks to all our early adopters who provided invaluable feedback on our incremental releases these past few months.

What is Immutant?

Immutant is an integrated suite of Clojure libraries backed by Undertow for web, HornetQ for messaging, Infinispan for caching, and Quartz for scheduling. Applications built with Immutant can optionally be deployed to a WildFly cluster for enhanced features. Its fundamental goal is to reduce the inherent incidental complexity in real world applications.

A few highlights of The Deuce compared to the previous 1.x series:

  • It uses the Undertow web server -- it's much faster, with WebSocket support
  • The source is licensed under the Apache Software License rather than LPGL
  • It's completely functional "embedded" in your app, i.e. no app server required
  • It may be deployed to latest WildFly for extra clustering features

How to try it

If you're already familiar with Immutant 1.x, you should take a look at our migration guide. It's our attempt at keeping track of what we changed in the Clojure namespaces.

The tutorials are another good source of information, along with the apidoc.

For a working example, check out our Feature Demo application!

Get It

There is no longer any "installation" step as there was in 1.x. Simply add the relevant dependency to your project as shown on Clojars.

What's next?

For the first release, we focused on the API and on usage outside of a container. For the next alpha, we plan on focusing on making in-container behavior more robust. Take a look at our current issues if you want to follow along.

Get In Touch

If you have any questions, issues, or other feedback about Immutant, you can always find us on #immutant on freenode or our mailing lists.

Immutant 1.1.4 Released

We're as happy as a kid at a basketball game to announce Immutant 1.1.4 - "OneFourMoreTheRoad".

This is strictly a bug fix release and, unless any new bugs are reported against it, possibly our last 1.x release. We are now focusing our efforts on The Deuce. We will make every reasonable effort to fix any bugs reported against 1.x, but we will only be adding features to 2.x. As always, view our road map here.

What is Immutant?

Immutant is an application server for Clojure. It's an integrated platform built on JBoss AS7 that aims to reduce the inherent incidental complexity in real world applications.

What's in this release?

The notable changes in this release are:

  • META-INF/ and WEB-INF/ directories on your resource path are now honored.
  • We've restored the needed bits to allow remote jmx connections.
  • Recent cider-nrepl snapshots require tools.nrepl to be on the classpath at the time the project.clj is resolved, so it's now available.
  • We no longer force tools.logging to use log4j. Note: If you were relying on that behavior, see IMMUTANT-464.

Get It

The simplest way to install or upgrade to 1.1.4 is via our Leiningen plugin:

$ lein immutant install 1.1.4

See our install page for more details. Once you have it installed, take a look at our tutorials.

What's next?

As we said above, we'll be focusing on Immutant 2, with a tentative alpha release in the next few weeks.

Get In Touch

If you have any questions, issues, or other feedback about Immutant, you can always find us on #immutant on freenode or our mailing lists.

Issues resolved in 1.1.4

  • [IMMUTANT-452] - Remote jmx not supported by default distribution
  • [IMMUTANT-453] - Immutant ignores logback config
  • [IMMUTANT-455] - META-INF and WEB-INF in a resource dir should be honored
  • [IMMUTANT-457] - Yet more com.sun packages need to be exposed in the sun.jdk module. This time, it's sound packages.
  • [IMMUTANT-459] - Recent cider-nrepl snapshots cause deployment to fail because it can't find tools.nrepl
  • [IMMUTANT-464] - Don't force tools.logging to use a particular provider

lein-immutant Plugin 1.2.2 Released

We just released version 1.2.2 of our Leiningen plugin. This release contains the following changes:

  • Active profiles are now honored for the immutant test task.
  • The immutant run and immutant server tasks no longer give spurious profile warnings under lein 2.4.2.

For the full list of changes, see the milestone.

Get it

If you're already using lein-immutant you probably already know how to do this, but just in case - to install it, add it to the :plugins list in your :user profile in ~/.lein/profiles.clj:

{:user {:plugins [[lein-immutant "1.2.2"]]}}

Get in touch

If you have any questions, issues, or other feedback, you can always find us on #immutant on freenode or you can file an issue on lein-immutant.

Immutant 1.1.3 Released

We're as happy as a kid with a banana to announce Immutant 1.1.3 - "Already?".

This is strictly a bug fix release and, unless any new bugs are reported against it, possibly our last 1.x release. We are now focusing our efforts on The Deuce. We will make every reasonable effort to fix any bugs reported against 1.x, but we will only be adding features to 2.x. As always, view our road map here.

What is Immutant?

Immutant is an application server for Clojure. It's an integrated platform built on JBoss AS7 that aims to reduce the inherent incidental complexity in real world applications.

What's in this release?

There are only three changes in this release:

  • Files in directories that are created after deployment under `resources/' are now visible on the classpath.
  • The helper classes needed for cider-nrepl to load are now exposed by the appropriate classloader.
  • Applications that depend on org.clojure/tools.logging and any Immutant namespace will now work properly when used outside of the container.

Get It

The simplest way to install or upgrade to 1.1.3 is via our Leiningen plugin:

$ lein immutant install 1.1.3

See our install page for more details. Once you have it installed, take a look at our tutorials.

What's next?

As we said above, we'll be focusing on Immutant 2, with a tentative release season beginning this summer.

Get In Touch

If you have any questions, issues, or other feedback about Immutant, you can always find us on #immutant on freenode or our mailing lists.

Issues resolved in 1.1.3

  • [IMMUTANT-446] - newly-generated cljs files don't get served without a server restart
  • [IMMUTANT-447] - Fix classpath issues with cider-nrepl middleware
  • [IMMUTANT-449] - immutant.logging fails outside of the container if tools.logging is loaded