Skip to content

Commit

Permalink
Adds circuit breaker
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbey37 committed Sep 17, 2018
1 parent 76cde44 commit 9e6b055
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 12 deletions.
1 change: 1 addition & 0 deletions applications/allocations-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ apply from: "$projectDir/../server.gradle"

dependencies {
compile project(":components:allocations")
compile "io.pivotal.spring.cloud:spring-cloud-services-starter-circuit-breaker"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
Expand All @@ -11,6 +12,7 @@
import java.util.TimeZone;

@EnableEurekaClient
@EnableCircuitBreaker
@SpringBootApplication
@ComponentScan({"io.pivotal.pal.tracker.allocations", "io.pivotal.pal.tracker.restsupport"})
public class App {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ spring.datasource.username=tracker
spring.datasource.url=jdbc:mysql://localhost:3306/tracker_allocations_dev?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false
registration.server.endpoint=http://registration-server
security.basic.enabled=false
management.security.enabled=false
management.security.enabled=false

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ spring.datasource.url=jdbc:mysql://localhost:3306/tracker_allocations_test?useSS
registration.server.endpoint=http://registration-server
security.basic.enabled=false
management.security.enabled=false

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000
1 change: 1 addition & 0 deletions applications/backlog-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ apply from: "$projectDir/../server.gradle"

dependencies {
compile project(":components:backlog")
compile "io.pivotal.spring.cloud:spring-cloud-services-starter-circuit-breaker"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
Expand All @@ -11,6 +12,7 @@
import java.util.TimeZone;

@EnableEurekaClient
@EnableCircuitBreaker
@SpringBootApplication
@ComponentScan({"io.pivotal.pal.tracker.backlog", "io.pivotal.pal.tracker.restsupport"})
public class App {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ spring.datasource.username=tracker
spring.datasource.url=jdbc:mysql://localhost:3306/tracker_backlog_dev?useSSL=false&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false
registration.server.endpoint=http://registration-server
security.basic.enabled=false
management.security.enabled=false
management.security.enabled=false

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ spring.datasource.url=jdbc:mysql://localhost:3306/tracker_backlog_test?useSSL=fa
registration.server.endpoint=http://registration-server
security.basic.enabled=false
management.security.enabled=false

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000
1 change: 1 addition & 0 deletions applications/timesheets-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ apply from: "$projectDir/../server.gradle"

dependencies {
compile project(":components:timesheets")
compile "io.pivotal.spring.cloud:spring-cloud-services-starter-circuit-breaker"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
Expand All @@ -11,6 +12,7 @@
import java.util.TimeZone;

@EnableEurekaClient
@EnableCircuitBreaker
@SpringBootApplication
@ComponentScan({"io.pivotal.pal.tracker.timesheets", "io.pivotal.pal.tracker.restsupport"})
public class App {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ spring.datasource.url=jdbc:mysql://localhost:3306/tracker_timesheets_dev?useSSL=
registration.server.endpoint=http://registration-server

security.basic.enabled=false
management.security.enabled=false
management.security.enabled=false

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ spring.datasource.url=jdbc:mysql://localhost:3306/tracker_timesheets_test?useSSL
registration.server.endpoint=http://registration-server
security.basic.enabled=false
management.security.enabled=false

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000
1 change: 1 addition & 0 deletions components/allocations/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencies {
compile project(":components:rest-support")
compile "org.springframework:spring-jdbc:$springVersion"
compile "com.netflix.hystrix:hystrix-javanica:1.5.6"

testCompile project(":components:test-support")
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package io.pivotal.pal.tracker.allocations;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestOperations;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ProjectClient {

private final Logger logger = LoggerFactory.getLogger(getClass());
private final Map<Long, ProjectInfo> projectsCache = new ConcurrentHashMap<>();
private final RestOperations restOperations;
private final String registrationServerEndpoint;
private final String endpoint;

public ProjectClient(RestOperations restOperations, String registrationServerEndpoint) {
this.restOperations= restOperations;
this.registrationServerEndpoint = registrationServerEndpoint;
this.restOperations = restOperations;
this.endpoint = registrationServerEndpoint;
}

@HystrixCommand(fallbackMethod = "getProjectFromCache")
public ProjectInfo getProject(long projectId) {
return restOperations.getForObject(registrationServerEndpoint + "/projects/" + projectId, ProjectInfo.class);
ProjectInfo project = restOperations.getForObject(endpoint + "/projects/" + projectId, ProjectInfo.class);

projectsCache.put(projectId, project);

return project;
}

public ProjectInfo getProjectFromCache(long projectId) {
logger.info("Getting project with id {} from cache", projectId);
return projectsCache.get(projectId);
}
}
}
1 change: 1 addition & 0 deletions components/backlog/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencies {
compile project(":components:rest-support")
compile "org.springframework:spring-jdbc:$springVersion"
compile "com.netflix.hystrix:hystrix-javanica:1.5.6"

testCompile project(":components:test-support")
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package io.pivotal.pal.tracker.backlog;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestOperations;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ProjectClient {

private final Logger logger = LoggerFactory.getLogger(getClass());
private final Map<Long, ProjectInfo> projectsCache = new ConcurrentHashMap<>();
private final RestOperations restOperations;
private final String endpoint;

Expand All @@ -12,7 +20,17 @@ public ProjectClient(RestOperations restOperations, String registrationServerEnd
this.endpoint = registrationServerEndpoint;
}

@HystrixCommand(fallbackMethod = "getProjectFromCache")
public ProjectInfo getProject(long projectId) {
return restOperations.getForObject(endpoint + "/projects/" + projectId, ProjectInfo.class);
ProjectInfo project = restOperations.getForObject(endpoint + "/projects/" + projectId, ProjectInfo.class);

projectsCache.put(projectId, project);

return project;
}

public ProjectInfo getProjectFromCache(long projectId) {
logger.info("Getting project with id {} from cache", projectId);
return projectsCache.get(projectId);
}
}
}
1 change: 1 addition & 0 deletions components/timesheets/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dependencies {
compile project(":components:rest-support")
compile "org.springframework:spring-jdbc:$springVersion"
compile "com.netflix.hystrix:hystrix-javanica:1.5.6"

testCompile project(":components:test-support")
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package io.pivotal.pal.tracker.timesheets;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.client.RestOperations;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ProjectClient {

private final Logger logger = LoggerFactory.getLogger(getClass());
private final Map<Long, ProjectInfo> projectsCache = new ConcurrentHashMap<>();
private final RestOperations restOperations;
private final String endpoint;

Expand All @@ -12,7 +20,17 @@ public ProjectClient(RestOperations restOperations, String registrationServerEnd
this.endpoint = registrationServerEndpoint;
}

@HystrixCommand(fallbackMethod = "getProjectFromCache")
public ProjectInfo getProject(long projectId) {
return restOperations.getForObject(endpoint + "/projects/" + projectId, ProjectInfo.class);
ProjectInfo project = restOperations.getForObject(endpoint + "/projects/" + projectId, ProjectInfo.class);

projectsCache.put(projectId, project);

return project;
}

public ProjectInfo getProjectFromCache(long projectId) {
logger.info("Getting project with id {} from cache", projectId);
return projectsCache.get(projectId);
}
}
}
1 change: 1 addition & 0 deletions manifest-allocations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ applications:
services:
- tracker-allocations-database
- tracker-service-registry
- tracker-circuit-breaker-dashboard
1 change: 1 addition & 0 deletions manifest-backlog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ applications:
services:
- tracker-backlog-database
- tracker-service-registry
- tracker-circuit-breaker-dashboard
1 change: 1 addition & 0 deletions manifest-timesheets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ applications:
services:
- tracker-timesheets-database
- tracker-service-registry
- tracker-circuit-breaker-dashboard

0 comments on commit 9e6b055

Please sign in to comment.