I am looking for the best way to implement a single-module Spring Boot project, which can run as multiple processes (1) serving REST API or (2) running one of many CLI processes.
Details:
We have three components in a simplified version of our application:
- Ingestion Process, which runs as a command line process. It connects to an external data source, fetches the data, and produces it to a Pulsar queue.
- Analysis Process, which also runs as a command line process. It consumes any data on the Pulsar queue, does some processing on it, and saves results to a MySQL database.
- Web REST App, which runs a server listening on port 8080. Provided REST APIs query the MySQL data and return reports based on already-analyzed data.
Question:
- If I create a Spring Boot Application, how do I have multiple entry points so when running it I can say which of the three processes I want to start.
- Use of ApplicationRunner will not work as it will start the web app + ingestion process + analysis process as a single process.
- Option is to write some logic in the main spring boot application as “dispatcher” so it starts the correct process based on some command line params. For example: java MyApp -run web-app or java MyApp -run ingestion-process
- I know, using multiple modules is an option but I think that adds complexity that our small team wants to avoid if we can as we build MVC of an application. Especially as I expect in the final version of the app to have 20-30 different processes to fetch data from different external data sources. I want to run each one as separate command line processes, even if each one is lightweight.
- I see Spring Modulith as a way to organize Spring projects in lightweight modules, but I don’t see anything about different applications I can start.
Any advice on how to architect will be useful. I am new to Spring Boot but have otherwise been building complex Java-based apps for 10+ years; and now trying to learn best practices within the Spring world.
I am looking for best practices on how to architect the app. We are a small team with deadline to deliver an MVP fast.