Reputation: 963
I'm sorry this is not a typical stackoverflow question, I'm not looking to fix some of my code, but I'm trying to find a solution for my application.
Context: I'm building an spring boot application that can expose/consume custom APIs (these can be REST or otherwise). The API connectors can be built and compiled outside the application, following a template.
The problem: I need a way to programatically load code compiled outside the application and run it inside my application with 0 downtime, I also need to be able to undeploy the jar no longer used.
Upvotes: 0
Views: 493
Reputation: 2443
I've used OSGi to achieve something like this, though it only involved making frontend apps packaged in jars available, rather than backend APIs.
First, I created an application with an embedded OSGi runtime (Apache Felix, specifically). These runtimes normally watch a local directory to find jar files they can load automatically; I used custom code to watch an AWS S3 bucket and loaded them explicitly when new files were uploaded to the bucket.
I setup listeners in my application for when the runtime loaded or unloaded plugin services that implemented my special marker interface and registered/unregistered them when these events happened.
When requests would come in, I would determine which plugin the requests were meant for via the request path and load needed files from the plugin archive.
Upvotes: 1