From 2a10ff0bb280e85920e7645f8e860f6372b84d87 Mon Sep 17 00:00:00 2001 From: Calvin Date: Thu, 17 Oct 2013 01:49:01 +0800 Subject: [PATCH] =?UTF-8?q?#286=20add=20hystrix=20demo=20back,=20improve?= =?UTF-8?q?=20GUI,=20=E5=A4=AA=E4=B9=85=E6=B2=A1=E5=81=9A=E5=89=8D?= =?UTF-8?q?=E5=8F=B0=E8=A6=81=E4=BA=86=E8=80=81=E5=91=BD=E4=BA=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demos/hystrix/web/HystrixDemoController.java | 5 +++-- .../main/webapp/WEB-INF/views/story/hystrix.jsp | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/examples/showcase/src/main/java/org/springside/examples/showcase/demos/hystrix/web/HystrixDemoController.java b/examples/showcase/src/main/java/org/springside/examples/showcase/demos/hystrix/web/HystrixDemoController.java index bfc029e0..b1dd0d78 100644 --- a/examples/showcase/src/main/java/org/springside/examples/showcase/demos/hystrix/web/HystrixDemoController.java +++ b/examples/showcase/src/main/java/org/springside/examples/showcase/demos/hystrix/web/HystrixDemoController.java @@ -16,6 +16,7 @@ import org.springside.examples.showcase.demos.hystrix.dependency.DependencyResou import org.springside.examples.showcase.demos.hystrix.service.UserService; import org.springside.examples.showcase.webservice.rest.RestException; import org.springside.examples.showcase.webservice.rest.UserDTO; +import org.springside.modules.web.MediaTypes; import com.google.common.collect.Maps; @@ -24,7 +25,7 @@ public class HystrixDemoController { private static Logger logger = LoggerFactory.getLogger(HystrixDemoController.class); - private static Map allStatus = Maps.newHashMap(); + private static Map allStatus = Maps.newLinkedHashMap(); static { allStatus.put("normal", "正常"); @@ -44,7 +45,7 @@ public class HystrixDemoController { return "story/hystrix"; } - @RequestMapping(value = "/hystrix/user/{id}", method = RequestMethod.GET) + @RequestMapping(value = "/hystrix/user/{id}", method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8) @ResponseBody public UserDTO getUser(@PathVariable("id") Long id) { try { diff --git a/examples/showcase/src/main/webapp/WEB-INF/views/story/hystrix.jsp b/examples/showcase/src/main/webapp/WEB-INF/views/story/hystrix.jsp index f866f963..33415f03 100644 --- a/examples/showcase/src/main/webapp/WEB-INF/views/story/hystrix.jsp +++ b/examples/showcase/src/main/webapp/WEB-INF/views/story/hystrix.jsp @@ -11,6 +11,15 @@ $(document).ready(function() { $("#hystrix-tab").addClass("active"); }); + + function accessHystrixService() { + $.ajax("${ctx}/hystrix/user/1") + .done( function(data,textStatus ,jqXHR) { + $('#hystrixResponse').text('Status: '+jqXHR.status+' ,Content: ' + jqXHR.responseText ); + }).fail( function(data,textStatus ,jqXHR) { + $('#hystrixResponse').text('Status:' + textStatus ); + }); + } @@ -20,9 +29,10 @@

Netflix Hystrix 是一个延迟与容错类库,通过独立访问远程系统、服务和第三方库的节点,在复杂的分布式系统里停止雪崩及提供恢复能力。

演示操作

-
依赖资源当前状态为:
-
访问服务:Hystrix服务、依赖资源
- +
依赖资源状态:
+
+
+

主要用户故事

  • 在默认的正常状态,访问Hystrix服务和依赖资源,均返回正常结果。