diff --git a/pom4ide.xml b/pom4ide.xml
index c0d8356844298a1cf53a9801710f99b36ea01ec9..17a1bbb91a7990dfb1b78d304a3d045d240d1be7 100644
--- a/pom4ide.xml
+++ b/pom4ide.xml
@@ -172,6 +172,18 @@
3.5
test
+
+ com.netflix.hystrix
+ hystrix-core
+ 1.5.18
+ test
+
+
+ org.springframework.cloud
+ spring-cloud-starter-hystrix
+ 1.4.7.RELEASE
+ test
+
diff --git a/src/test/java/com/alibaba/demo/hystrix/EmployeeService.java b/src/test/java/com/alibaba/demo/hystrix/EmployeeService.java
new file mode 100644
index 0000000000000000000000000000000000000000..1579f342e235cd80fc54f871d36adf37458fbe30
--- /dev/null
+++ b/src/test/java/com/alibaba/demo/hystrix/EmployeeService.java
@@ -0,0 +1,12 @@
+package com.alibaba.demo.hystrix;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public abstract class EmployeeService {
+ public abstract void getEmployee(int employeeId);
+
+ public void fallbackMethod(int employeeid) {
+ ThreadLocalUtil.addDataToThreadLocalMap("ErrorResponse", "Fallback response:: No employee details available temporarily");
+ }
+}
diff --git a/src/test/java/com/alibaba/demo/hystrix/EmployeeServiceImpl.java b/src/test/java/com/alibaba/demo/hystrix/EmployeeServiceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..d59a654408e820a6ef900db84efeed90123a5ca1
--- /dev/null
+++ b/src/test/java/com/alibaba/demo/hystrix/EmployeeServiceImpl.java
@@ -0,0 +1,26 @@
+package com.alibaba.demo.hystrix;
+
+import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
+import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.stereotype.Service;
+
+@Service
+public class EmployeeServiceImpl extends EmployeeService {
+
+ @HystrixCommand(fallbackMethod = "fallbackMethod", commandProperties = {
+ @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "900"),
+ @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "10") })
+ public void getEmployee(int employeeId) {
+ System.out.println("Getting Employee details for " + employeeId + ", threadLocalUtil : " + ThreadLocalUtil.getDataFromThreadLocalMap("EMPLOYEE_ID"));
+ String response = restTemplate.exchange("http://localhost:8011/findEmployeeDetails/{employeeid}",
+ HttpMethod.GET, null, new ParameterizedTypeReference() {
+ }, employeeId).getBody();
+
+ ThreadLocalUtil.addDataToThreadLocalMap("Response", response);
+ }
+
+ @Autowired
+ RestTemplate restTemplate;
+}
diff --git a/src/test/java/com/alibaba/demo/hystrix/HystrixHook.java b/src/test/java/com/alibaba/demo/hystrix/HystrixHook.java
new file mode 100644
index 0000000000000000000000000000000000000000..d51e2a26da0950237f6b805c77a123b248694d54
--- /dev/null
+++ b/src/test/java/com/alibaba/demo/hystrix/HystrixHook.java
@@ -0,0 +1,52 @@
+package com.alibaba.demo.hystrix;
+
+import com.netflix.hystrix.HystrixInvokable;
+import com.netflix.hystrix.exception.HystrixRuntimeException;
+import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
+import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableDefault;
+import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+public class HystrixHook extends HystrixCommandExecutionHook {
+
+ private HystrixRequestVariableDefault> hrv = new HystrixRequestVariableDefault<>();
+
+ @Override
+ public void onStart(HystrixInvokable commandInstance) {
+ HystrixRequestContext.initializeContext();
+ getThreadLocals();
+ }
+
+ @Override
+ public void onExecutionStart(HystrixInvokable commandInstance) {
+ setThreadLocals();
+ }
+
+
+ @Override
+ public void onFallbackStart(HystrixInvokable commandInstance) {
+ setThreadLocals();
+ }
+
+
+ @Override
+ public void onSuccess(HystrixInvokable commandInstance) {
+ HystrixRequestContext.getContextForCurrentThread().shutdown();
+ super.onSuccess(commandInstance);
+ }
+
+ @Override
+ public Exception onError(HystrixInvokable commandInstance, HystrixRuntimeException.FailureType failureType, Exception e) {
+ HystrixRequestContext.getContextForCurrentThread().shutdown();
+ return super.onError(commandInstance, failureType, e);
+ }
+
+ private void getThreadLocals() {
+ hrv.set(ThreadLocalUtil.getThreadLocalData());
+ }
+
+ private void setThreadLocals() {
+ ThreadLocalUtil.setThreadLocalData(hrv.get());
+ }
+}
diff --git a/src/test/java/com/alibaba/demo/hystrix/MainApplication.java b/src/test/java/com/alibaba/demo/hystrix/MainApplication.java
new file mode 100644
index 0000000000000000000000000000000000000000..00ab3ba6dc6f9b83e0ac013213779202309db5af
--- /dev/null
+++ b/src/test/java/com/alibaba/demo/hystrix/MainApplication.java
@@ -0,0 +1,11 @@
+package com.alibaba.demo.hystrix;
+
+import com.netflix.hystrix.strategy.HystrixPlugins;
+import org.springframework.boot.SpringApplication;
+
+public class MainApplication {
+ public static void main(String[] args) {
+ HystrixPlugins.getInstance().registerCommandExecutionHook(new HystrixHook());
+ SpringApplication.run(Abc.class, args);
+ }
+}
diff --git a/src/test/java/com/alibaba/demo/hystrix/ThreadLocalUtil.java b/src/test/java/com/alibaba/demo/hystrix/ThreadLocalUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..17be5c3d72dd126d94a9217e79385a13ebd15f46
--- /dev/null
+++ b/src/test/java/com/alibaba/demo/hystrix/ThreadLocalUtil.java
@@ -0,0 +1,50 @@
+package com.alibaba.demo.hystrix;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class ThreadLocalUtil {
+
+ private static ThreadLocal> transmittableThreadLocal = new ThreadLocal<>();
+
+ public static ConcurrentHashMap getThreadLocalData() {
+ return transmittableThreadLocal.get();
+ }
+
+ public static void setThreadLocalData(ConcurrentHashMap data) {
+ transmittableThreadLocal.set(data);
+ }
+
+ public static void addDataToThreadLocalMap(String key, Object value) {
+ Map existingDataMap = transmittableThreadLocal.get();
+ if (value != null) {
+ existingDataMap.put(key, value);
+ }
+ }
+
+ public static Object getDataFromThreadLocalMap(String key) {
+ Map existingDataMap = transmittableThreadLocal.get();
+ return existingDataMap.get(key);
+ }
+
+ public static void clearThreadLocalDataMap() {
+ if (transmittableThreadLocal != null)
+ transmittableThreadLocal.remove();
+ }
+
+ public static Object getRequestData(String key) {
+ Map existingDataMap = transmittableThreadLocal.get();
+ if (existingDataMap != null) {
+ return existingDataMap.get(key);
+ }
+ return "-1";
+ }
+
+
+
+ public static void initThreadLocals() {
+ transmittableThreadLocal.set(new ConcurrentHashMap<>());
+ String requestId = "REQUEST_ID_" + System.currentTimeMillis();
+ addDataToThreadLocalMap("REQUEST_ID", requestId);
+ }
+}