Commit 0e45f7d5 authored by mohammad.salama's avatar mohammad.salama

Services Register to Eureka and Call API by Service NAME

parent bcdd8d6b
......@@ -10,6 +10,7 @@
<module name="DiscAndReg" />
<module name="UserService" />
<module name="DataBase" />
<module name="CloudGateway" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/CloudGateway/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/CloudGateway/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/DataBase/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/DataBase/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/DiscAndReg/src/main/java" charset="UTF-8" />
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>MicroServices</artifactId>
<groupId>org.example</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>CloudGateway</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
\ No newline at end of file
package org.example;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ public class DataBaseApp
public static void main(String[] args)
{
init();
System.out.println("Done Filling");
SpringApplication.run(DataBaseApp.class, args);
}
public static void init()
......
......@@ -17,11 +17,15 @@ public class UserService
{
@Autowired
RestTemplate restTemplate;
String UserDBURL = "http://localhost:8081/users-db/";
String muURL1 = "http://localhost:8082/users/{user id}";
String muURL2 = "http://localhost:8082/users/weather/{flight id}";
String FlightDBURL = "http://localhost:8081/flights-db/";
String WeatherURL = "http://localhost:8083/weather/";
// String UserDBURL = "http://localhost:8081/users-db/";
// String FlightDBURL = "http://localhost:8081/flights-db/";
// String WeatherURL = "http://localhost:8083/weather/";
//
String UserDBURL = "http://database-service/users-db/";
String FlightDBURL = "http://database-service/flights-db/";
String WeatherURL = "http://weather-service/weather/";
@RequestMapping("/{userID}")
public List<Flight> getFlights(@PathVariable("userID") String userID)
......@@ -30,7 +34,7 @@ public class UserService
if (user == null) return new ArrayList<>();
System.out.println("Welcome : " + user.getName());
List<Flight> ans = new ArrayList<>();
System.out.println("Ans size is " + user.getFlights().size());
/// System.out.println("Ans size is " + user.getFlights().size());
for (String flightID : user.getFlights())
{
......@@ -44,7 +48,6 @@ public class UserService
@RequestMapping("/weather/{flightID}")
public Weather getWeather(@PathVariable("flightID") String flightID)
{
System.out.println("Getting Weather Req");
Flight flight = restTemplate.getForObject(FlightDBURL+flightID , Flight.class);
if (flight.getDestination().isEmpty() ) return new Weather();
......
......@@ -3,6 +3,7 @@ package org.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
......@@ -15,7 +16,10 @@ public class UserServiceApp
{
SpringApplication.run(UserServiceApp.class, args);
}
@Bean
@LoadBalanced
public RestTemplate getRestTemplate()
{
return new RestTemplate();
......
......@@ -2,6 +2,7 @@ package org.example;
import org.codehaus.jettison.json.JSONException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -16,21 +17,28 @@ public class WeatherService
{
@Autowired
RestTemplate restTemplate;
/*@Value("${api.key}")
String myAPIKey;*/
String myAPIKey = "57afea8fc6e142f29f2115632242604";
String prefURL = "http://api.weatherapi.com/v1/current.json?key="+myAPIKey + "&q=";
String prefURL = "http://api.weatherapi.com/v1/current.json?key="+ myAPIKey + "&q=";
String sufURL = "&aqi=yes";
@RequestMapping("/{city}")
public Weather getWeather(@PathVariable("city") String city) throws IOException {
System.out.println("My Api = " + myAPIKey);
if (city.isEmpty())
{
System.out.println("City is Empty");
return new Weather();
}
Weather weather = new Weather();
try
{
weather = new Weather(prefURL + city + sufURL);
} catch (JSONException e)
{
System.out.println("EERRRERERER");
//log
}
return weather;
......
......@@ -3,6 +3,7 @@ package org.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
......@@ -15,7 +16,9 @@ public class WeatherServiceApp
SpringApplication.run(WeatherServiceApp.class, args);
}
//@LoadBalanced
@Bean
@LoadBalanced
public RestTemplate getRestTemplate()
{
return new RestTemplate();
......
server.port=8083
spring.application.name=weather-service
spring.main.allow-bean-definition-overriding=true
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
api.key=57afea8fc6e142f29f2115632242604
\ No newline at end of file
server.port=8083
spring.application.name=weather-service
spring.main.allow-bean-definition-overriding=true
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
api.key=57afea8fc6e142f29f2115632242604
\ No newline at end of file
......@@ -13,6 +13,7 @@
<module>WeatherService</module>
<module>DataBase</module>
<module>DiscAndReg</module>
<module>CloudGateway</module>
</modules>
<properties>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment