Defining a SPI in Clojure
- by Joe Holloway
I'm looking for an idiomatic way(s) to define an interface in Clojure that can be implemented by an external "service provider". My application would locate and instantiate the service provider module at runtime and delegate certain responsibilities to it.
Let's say, for example, that I'm implementing a RPC mechanism and I want to allow a custom middleware to be injected at configuration time. This middleware could pre-process the message, discard messages, wrap the message handler with logging, etc.
I know several ways to do this if I fall back to Java reflection, but feel that implementing it in Clojure would help my understanding.
(Note, I'm using SPI in a general sense here, not specifically referring to the way it's defined in the JAR file specification)
Thanks