feat: CentralManagerService uses eureka discovery to access data

Tento commit je obsažen v:
Jean-Remy Hok 2022-01-13 16:13:52 +01:00
rodič d3fd84b0c1
revize b174d3fff9
2 změnil soubory, kde provedl 40 přidání a 0 odebrání

Zobrazit soubor

@ -2,10 +2,19 @@ package fr.insa.arm.CentralManagerService;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication @SpringBootApplication
public class CentralManagerServiceApplication { public class CentralManagerServiceApplication {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(CentralManagerServiceApplication.class, args); SpringApplication.run(CentralManagerServiceApplication.class, args);
} }

Zobrazit soubor

@ -1,10 +1,41 @@
package fr.insa.arm.CentralManagerService.controller; package fr.insa.arm.CentralManagerService.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.Map;
@RestController @RestController
@RequestMapping("/centralManager") @RequestMapping("/centralManager")
public class CentralManagerController { public class CentralManagerController {
@Autowired
private RestTemplate restTemplate;
// Urls
final private static String rooms = "http://RoomsService/rooms/";
final private static String lightSensor = "http://LightSensorService/lightSensor/";
final private static String temperatureSensor = "http://TemperatureSensorService/temperatureSensor/";
final private static String gazSensor = "http://GazSensorService/gazSensor/";
final private static String co2Sensor = "http://GazSensorService/co2Sensor/";
final private static String window = "http://WindowService/window/";
final private static String door = "http://DoorService/door/";
final private static String light = "http://LightService/light/";
final private static String heating = "http://HeatingService/heating/";
final private static String cooling = "http://CoolingService/cooling/";
final private static String alarm = "http://AlarmService/alarm/";
@GetMapping("/")
public String test() {
String result = "";
Integer i = restTemplate.postForObject(lightSensor, "", Integer.class);
restTemplate.put(lightSensor + i, 12.0, Float.class);
Integer id = restTemplate.getForObject(lightSensor + i, Integer.class);
return id != null ? id.toString() : "Error";
}
} }