I’m working on Clojure app where a client needs to send some commands to a server. These will happen in quite large volumes, so I’d like it to be reasonably efficient, both in terms of processing and over-the-wire serialised size.
What would be the best way of doing this in Clojure?
Currently I’m thinking of:
- Creating a simple standard representation e.g. {:command-id 1, :params [1 2 3 “abc”]}
- Serialising using some efficient Java library such as Kryo, and configuring it to understand the Clojure data types
- Hacking together an appropriate Client/Server socket implementation using the Java NIO libraries for the transmission over TCP/IP
However this seems a little convoluted and I’m sure other people have come up with smarter approaches. Any ideas / advice much appreciated!
If parameters aren’t too big and source is trusted, why not send s-expressions back and fort,
Clojure being a LISP dialect code is data.
EDIT:
For safety, after reading the string you check the command against a valid set of commands,
or you can use a library designed for this such as
http://github.com/Licenser/clj-sandbox