G
G
Germanjon2021-10-26 10:42:15
Java
Germanjon, 2021-10-26 10:42:15

Is it possible to dynamically add WebAPI?

Good afternoon, dear colleagues.

Question from a total newbie: Is it possible to add an API to a Java Spring application without restarting?

Situation:
1. There is a program written in Java Spring that accepts requests for 20+ APIs and, depending on the set of rules, redirects (proxies) them to third-party systems/services. API like https://software/servicename/v1 .
2. When adding a new service or adding a new version (in fact - adding or changing the API for third-party recipients), you have to restart the system.

What I would like:
In some folder, XML or similar files are created with a description of the behavior rules for the request. The application regularly parses them, and if a new one appears, it automatically starts "listening" to the new API.

Question - is it possible to implement this or similar? In which direction to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vamp, 2021-10-26
@Germanjon

1. Blue-green deployment . Launch two instances of your application. One of them is conventionally called green, the other blue. Put nginx/haproxy in front of them and set up proxying of all requests to the green instance. When it comes time to make changes, make them on the blue instance, restart it, and reconfigure proxying of all traffic from the green instance to the blue one. The next time you do the same, but with a green instance.
This option does not require a single line of code changes.
2. In an endless loop with a pause of 1 second between iterations, read files with a configuration from the desired folder. Then you stop the services for which there was no definition in the config, start the services for which there is a definition, and restart the services whose config has changed. This has already been implemented inspring boot externalized configuration , but nothing prevents you from doing it manually.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question