Using MQTT in Common Lisp with ABCL and the Eclipse Paho client

I have recently written some posts about using Clojure to take advantage of Java libraries. The idea of using a Lisp language that can take advantage of existing Java infrastructure is something that can however be achieved in different ways, Clojure being but one of them.

On the Scheme side I know at least GNU Kawa and SISC, and on the Common Lisp side Armed Bear Common Lisp (ABCL). Since I lean towards CL more than Scheme I have made some experiences with ABCL (including some comparisons with Clojure in terms of syntax which I will likely post about since the original content, sent to the ABCL mailing list as a pastebin link, is no longer accessible).

This is the simple MQTT example, which I previously wrote in Clojure, written in Common Lisp and using ABCL Java interop.

The use of ABCL Java facilities is of course essential to use the the Java libraries (see Hans Hübner’s post about using ABCL to parse Excel files using Apache POI for another example of the usefulness of this, and much better code-wise than my own code), so those parts aren’t portable to other CL implementations, but the rest of the code is. This means that by using ABCL one can use CL – which is a standartised language with multiple implementations – for the code, and that even with non-portable parts (which can be isolated) the bulk of the code is implementation independent.

Additionally (and at least equally important) it allows the use of Common Lisp wherever a JVM exists, which in itself is an advantage to those who know the language and do not want to program  in Clojure for whatever reason. There are several Java interop options built into ABCL – the example above uses  JSS 3, but there are also the included primitives and even Rich Hickey’s pre-Clojure framework JFLI.