Commit 58768210 authored by mohammad.salama's avatar mohammad.salama

Replication Returned for UserService

parent c2587404
......@@ -9,6 +9,7 @@
<module name="WeatherService" />
<module name="DiscAndReg" />
<module name="UserService" />
<module name="UserServiceReplica" />
<module name="DataBase" />
<module name="CloudGateway" />
</profile>
......@@ -24,6 +25,7 @@
<module name="DataBase" options="-parameters" />
<module name="DiscAndReg" options="-parameters" />
<module name="UserService" options="-parameters" />
<module name="UserServiceReplica" options="-parameters" />
<module name="WeatherService" options="-parameters" />
</option>
</component>
......
......@@ -11,6 +11,8 @@
<file url="file://$PROJECT_DIR$/ServiceDiscoveryAndRegistry/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/UserService/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/UserService/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/UserServiceReplica/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/UserServiceReplica/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/WeatherService/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/WeatherService/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/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>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.1</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>UserServiceReplica</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>UserServiceReplica</name>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<java.version>17</java.version>
<spring-cloud.version>2022.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>DataBase</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>WeatherService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.11</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.4.11</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>netflix-candidates</id>
<name>Netflix Candidates</name>
<url>https://artifactory-oss.prod.netflix.net/artifactory/maven-oss-candidates</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
\ No newline at end of file
package org.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping("/users")
public class UserService
{
@Autowired
RestTemplate restTemplate;
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)
{
User user = restTemplate.getForObject(UserDBURL+userID , User.class);
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());
for (String flightID : user.getFlights())
{
Flight flight = restTemplate.getForObject(FlightDBURL+flightID , Flight.class);
ans.add(flight);
}
System.out.println(ans);
return ans;
}
@RequestMapping("/weather/{flightID}")
public Weather getWeather(@PathVariable("flightID") String flightID)
{
Flight flight = restTemplate.getForObject(FlightDBURL+flightID , Flight.class);
if (flight.getDestination().isEmpty() ) return new Weather();
String city = flight.getDestination();
Weather weather = restTemplate.getForObject(WeatherURL+city , Weather.class);
System.out.println(weather);
return weather;
}
}
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;
@SpringBootApplication
@EnableDiscoveryClient
public class UserServiceApp
{
public static void main(String[] args)
{
SpringApplication.run(UserServiceApp.class, args);
}
@Bean
@LoadBalanced
public RestTemplate getRestTemplate()
{
return new RestTemplate();
}
}
\ No newline at end of file
server.port=8085
spring.main.allow-bean-definition-overriding=true
spring.application.name=user-service
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
\ No newline at end of file
server.port=8085
spring.main.allow-bean-definition-overriding=true
spring.application.name=user-service
eureka.client.serviceUrl.defaultZone= ${EUREKA_URL:http://localhost:8761/eureka/}
\ No newline at end of file
......@@ -13,6 +13,7 @@
<module>DataBase</module>
<module>DiscAndReg</module>
<module>CloudGateway</module>
<module>UserServiceReplica</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