HttpClient for nodes, registration to Discovery

This commit is contained in:
2024-11-23 23:58:27 +02:00
parent d15f8c2629
commit 03b1ea3b6d
6 changed files with 92 additions and 6 deletions

View File

@@ -4,14 +4,33 @@ import jakarta.persistence.EntityManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static Logger logger = LogManager.getLogger(Main.class);
public static void main(String[] args) {
public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
logger.info("Node up.");
EntityManager em = Data.getEntityManager();
logger.info("Connected to database: << symphony >>");
em.close();
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("http://symphony-discovery:8083/check"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) {
logger.info("Node successfully registered to Discovery");
}
}
}