From 3c31664ea0576676f94d08b0950f467508668911 Mon Sep 17 00:00:00 2001 From: sbalachandran Date: Sun, 7 Aug 2016 22:06:57 -0400 Subject: [PATCH] Updated with Hystrix integration to spring app --- .../java/com/baeldung/hystrix/AppConfig.java | 13 +++++++++++++ .../com/baeldung/hystrix/CommandHelloWorld.java | 0 .../com/baeldung/hystrix/HystrixAspect.java | 7 +++++++ .../baeldung/hystrix/HystrixCircuitBreaker.java | 7 +++++++ .../com/baeldung/hystrix/HystrixController.java | 17 +++++++++++++++++ .../hystrix/RemoteServiceSimulator.java | 15 --------------- .../hystrix/RemoteServiceTestCommand.java | 0 .../hystrix/RemoteServiceTestSimulator.java | 0 .../baeldung/hystrix/SpringExistingClient.java | 7 +++++++ .../src/main/resources/application.properties | 0 10 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 hystrix/src/main/java/com/baeldung/hystrix/AppConfig.java rename hystrix/src/{test => main}/java/com/baeldung/hystrix/CommandHelloWorld.java (100%) create mode 100644 hystrix/src/main/java/com/baeldung/hystrix/HystrixAspect.java create mode 100644 hystrix/src/main/java/com/baeldung/hystrix/HystrixCircuitBreaker.java create mode 100644 hystrix/src/main/java/com/baeldung/hystrix/HystrixController.java delete mode 100644 hystrix/src/main/java/com/baeldung/hystrix/RemoteServiceSimulator.java rename hystrix/src/{test => main}/java/com/baeldung/hystrix/RemoteServiceTestCommand.java (100%) rename hystrix/src/{test => main}/java/com/baeldung/hystrix/RemoteServiceTestSimulator.java (100%) create mode 100644 hystrix/src/main/java/com/baeldung/hystrix/SpringExistingClient.java create mode 100644 hystrix/src/main/resources/application.properties diff --git a/hystrix/src/main/java/com/baeldung/hystrix/AppConfig.java b/hystrix/src/main/java/com/baeldung/hystrix/AppConfig.java new file mode 100644 index 0000000000..8102428e9a --- /dev/null +++ b/hystrix/src/main/java/com/baeldung/hystrix/AppConfig.java @@ -0,0 +1,13 @@ +package com.baeldung.hystrix; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ApplicationContext; + +@SpringBootApplication +public class AppConfig { + + public static void main(String[] args) { + SpringApplication.run(AppConfig.class, args); + } +} diff --git a/hystrix/src/test/java/com/baeldung/hystrix/CommandHelloWorld.java b/hystrix/src/main/java/com/baeldung/hystrix/CommandHelloWorld.java similarity index 100% rename from hystrix/src/test/java/com/baeldung/hystrix/CommandHelloWorld.java rename to hystrix/src/main/java/com/baeldung/hystrix/CommandHelloWorld.java diff --git a/hystrix/src/main/java/com/baeldung/hystrix/HystrixAspect.java b/hystrix/src/main/java/com/baeldung/hystrix/HystrixAspect.java new file mode 100644 index 0000000000..2ea0163ab1 --- /dev/null +++ b/hystrix/src/main/java/com/baeldung/hystrix/HystrixAspect.java @@ -0,0 +1,7 @@ +package com.baeldung.hystrix; + +/** + * Created by sbalachandran on 8/5/2016. + */ +public class HystrixAspect { +} diff --git a/hystrix/src/main/java/com/baeldung/hystrix/HystrixCircuitBreaker.java b/hystrix/src/main/java/com/baeldung/hystrix/HystrixCircuitBreaker.java new file mode 100644 index 0000000000..9377d83495 --- /dev/null +++ b/hystrix/src/main/java/com/baeldung/hystrix/HystrixCircuitBreaker.java @@ -0,0 +1,7 @@ +package com.baeldung.hystrix; + +/** + * Created by sbalachandran on 8/5/2016. + */ +public class HystrixCircuitBreaker { +} diff --git a/hystrix/src/main/java/com/baeldung/hystrix/HystrixController.java b/hystrix/src/main/java/com/baeldung/hystrix/HystrixController.java new file mode 100644 index 0000000000..a8ca0adef2 --- /dev/null +++ b/hystrix/src/main/java/com/baeldung/hystrix/HystrixController.java @@ -0,0 +1,17 @@ +package com.baeldung.hystrix; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HystrixController { + + @Autowired + private SpringExistingClient client; + + @RequestMapping("/") + public String index() throws InterruptedException{ + return client.invokeRemoteService(); + } +} diff --git a/hystrix/src/main/java/com/baeldung/hystrix/RemoteServiceSimulator.java b/hystrix/src/main/java/com/baeldung/hystrix/RemoteServiceSimulator.java deleted file mode 100644 index 3efd579d84..0000000000 --- a/hystrix/src/main/java/com/baeldung/hystrix/RemoteServiceSimulator.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.hystrix; - - -public class RemoteServiceSimulator { - - public String checkSomething(final long timeout) throws InterruptedException { - - System.out.print(String.format("Waiting %sms. ", timeout)); - - // to simulate a real world delay in processing. - Thread.sleep(timeout); - - return "Done waiting."; - } -} diff --git a/hystrix/src/test/java/com/baeldung/hystrix/RemoteServiceTestCommand.java b/hystrix/src/main/java/com/baeldung/hystrix/RemoteServiceTestCommand.java similarity index 100% rename from hystrix/src/test/java/com/baeldung/hystrix/RemoteServiceTestCommand.java rename to hystrix/src/main/java/com/baeldung/hystrix/RemoteServiceTestCommand.java diff --git a/hystrix/src/test/java/com/baeldung/hystrix/RemoteServiceTestSimulator.java b/hystrix/src/main/java/com/baeldung/hystrix/RemoteServiceTestSimulator.java similarity index 100% rename from hystrix/src/test/java/com/baeldung/hystrix/RemoteServiceTestSimulator.java rename to hystrix/src/main/java/com/baeldung/hystrix/RemoteServiceTestSimulator.java diff --git a/hystrix/src/main/java/com/baeldung/hystrix/SpringExistingClient.java b/hystrix/src/main/java/com/baeldung/hystrix/SpringExistingClient.java new file mode 100644 index 0000000000..b08f61a777 --- /dev/null +++ b/hystrix/src/main/java/com/baeldung/hystrix/SpringExistingClient.java @@ -0,0 +1,7 @@ +package com.baeldung.hystrix; + +/** + * Created by sbalachandran on 8/5/2016. + */ +public class SpringExistingClient { +} diff --git a/hystrix/src/main/resources/application.properties b/hystrix/src/main/resources/application.properties new file mode 100644 index 0000000000..e69de29bb2