Home > front end >  Connecting two spring boot applications to respond to each other
Connecting two spring boot applications to respond to each other

Time:01-25

My problem is the following: I want to be able to start one spring application from another. I have one application and other is microservice which should enable from time to time. How can I achieve this?

In the ideal scenario if application receive rest request from the other one, it should turn on, but I know its impossible since it can't communicate if it's not working.

CodePudding user response:

This a perfect use case for serverless computing. But if really want to avoid that and want to start and stop pods in kubernetes cluster you can use the kubernetes api from the primaty process.

Alternatively, you can start the secondary service in the same Docker container with Runtime.exec()

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("java -jar secondary.jar");

The primary process will need to listen for a call emanating from the secondary service to indicate the secondary service is up.

When secondary is known to be up, primary can make the call. Or it can simple keep retrying until a good response is received.

When the secondary has completed its work it will need to System.exit(). (Or can call primary to terminate it)

  • Related