Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ Sandbox to play with spring cloud features
| Name | Description | Default port | Details |
|----------------------|---------------------------|--------------|----------------------------------------------------|
| Configuration server | Configuration server | 8888 | You should set an `JAVA_CLUB_SRC_HOME` variable which points to the folder where your java club sources are checked out. <br/>Configs URL example: http://localhost:8888/cloud/master |
| Discovery server | Discovery server | 8761 | |
| Discovery server | Discovery server | 8761 | Eureka server for services registration. |


## Service
| Name | Description | Default port | Details |
|----------------------|-----------------------------|--------------|--------------------------------------------------|
| Rating service | Rating Calculation Service | 8081 | |
| Hackster service| Hackster Detection Service | 8082| |
| Realtor service| Realtor Api Service | 8080| To call other services used Feign, RestTemplate |
| Storage service| Storage of Apartment Records Service | 8091| H2 based service for ApartmentRecord data storage. |


# Dev
Expand All @@ -30,6 +32,7 @@ mvn clean install

```
## TODO Items
- [ ] Check Feign Fallback ?
- [x] Storage Service (persistance + eurika client)
- [x] Rieltor Service
- [x] All eurika clients add eurika server address to properties
Expand Down
1 change: 0 additions & 1 deletion config/rating-service.properties

This file was deleted.

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
<module>rating-service</module>
<module>hackster-service</module>
<module>realtor-service</module>
<module>storage-service</module>>
</modules>
</project>
4 changes: 4 additions & 0 deletions realtor-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<artifactId>lombok</artifactId>
<version>1.16.12</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Data
@ToString
public class ApartmentRecord {
@NonNull
private String location;
Expand All @@ -17,4 +18,6 @@ public class ApartmentRecord {
private String phone;
@NonNull
private String realtorName;
@NonNull
private String mail;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.lohika.jclub;

import feign.Headers;
import feign.RequestLine;

/**
* Created by omuliarevych on 6/8/17.
*/
public interface ApartmentRecordClient {

@RequestLine("POST /apartmentRecords")
@Headers("Content-Type: application/json")
void storeApartment(ApartmentRecord apartmentRecord);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class RealtorController {
@Autowired
private RestTemplate restTemplate;

@Autowired
private RealtorService realtorService;

@PostMapping("/apartments")
public void addApartment(@RequestBody ApartmentRecord apartmentRecord) {
ResponseEntity<Boolean> isHackster =
Expand All @@ -29,6 +32,15 @@ public void addApartment(@RequestBody ApartmentRecord apartmentRecord) {
log.info("Is hackster " + isHackster);
}

@PostMapping("/storeApartments")
public void storeApartment(@RequestBody ApartmentRecord apartmentRecord) {
realtorService.storeApartment(apartmentRecord);
/*ApartmentRecordClient apartmentRecordClient = Feign.builder().encoder(new JacksonEncoder())
.decoder(new JacksonDecoder()).target(ApartmentRecordClient.class, "http://storage-service");
apartmentRecordClient.storeApartment(apartmentRecord);*/
log.info("Stored");
}

@RequestMapping("/service-instances/{applicationName}")
public List<ServiceInstance> serviceInstancesByApplicationName(@PathVariable String applicationName) {
return this.discoveryClient.getInstances(applicationName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package com.lohika.jclub;

import lombok.extern.slf4j.Slf4j;
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.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.client.RestTemplate;

@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class RealtorServiceApplication {

/* @Bean
public FeignApartmentFallback createFeignFallback() {
return new FeignApartmentFallback();
}*/

public static void main(String[] args) {
SpringApplication.run(RealtorServiceApplication.class, args);
}
Expand All @@ -21,3 +32,19 @@ public RestTemplate restTemplate() {
return new RestTemplate();
}
}

@FeignClient(value = "storage-service", fallback = FeignApartmentFallback.class)
interface RealtorService {
@PostMapping("/apartmentRecords")
void storeApartment(ApartmentRecord apartmentRecord);
}

@Slf4j
@Component
class FeignApartmentFallback implements RealtorService {

@Override
public void storeApartment(ApartmentRecord apartmentRecord) {
log.error("Error: {}", apartmentRecord);
}
}
24 changes: 24 additions & 0 deletions storage-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
target/
!.mvn/wrapper/maven-wrapper.jar

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
81 changes: 81 additions & 0 deletions storage-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<groupId>com.lohika.jclub</groupId>
<artifactId>storage-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>storage-service</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR1</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</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>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.lohika.jclub;

import lombok.*;

import javax.persistence.Entity;
import javax.persistence.Id;

@NoArgsConstructor
@AllArgsConstructor
@Data
@Entity
public class ApartmentRecord {
@NonNull
private String location;
@NonNull
private double price;
@NonNull
private double sqft;
@NonNull
private String phone;
@NonNull
private String realtorName;
@Id
private String mail;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.lohika.jclub;

import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

/**
* Created by omuliarevych on 6/8/17.
*/
@RepositoryRestResource
public interface ApartmentRepository extends CrudRepository<ApartmentRecord, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.lohika.jclub;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@EnableDiscoveryClient
@SpringBootApplication
public class StorageServiceApplication {

public static void main(String[] args) {
SpringApplication.run(StorageServiceApplication.class, args);
}
}
2 changes: 2 additions & 0 deletions storage-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
spring.application.name=storage-service
server.port=8091
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.lohika.jclub;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class StorageServiceApplicationTests {

@Test
public void contextLoads() {
}

}