zoukankan      html  css  js  c++  java
  • spring cloud spring-hystrix

    <dependencyManagement>
    		<dependencies>
    			<dependency>
    				<groupId>org.springframework.cloud</groupId>
    				<artifactId>spring-cloud-dependencies</artifactId>
    				<version>Dalston.SR3</version>
    				<type>pom</type>
    				<scope>import</scope>
    			</dependency>
    		</dependencies>
    	</dependencyManagement>
    	<dependencies>
    		<dependency>
    			<groupId>org.springframework.cloud</groupId>
    			<artifactId>spring-cloud-starter-config</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.cloud</groupId>
    			<artifactId>spring-cloud-starter-eureka</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.cloud</groupId>
    			<artifactId>spring-cloud-starter-ribbon</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.cloud</groupId>
    			<artifactId>spring-cloud-starter-hystrix</artifactId>
    		</dependency>
    		
    	</dependencies>
    

      

    @Service
    @DefaultProperties(defaultFallback = "getMemberFallback")
    public class MemberService {
    
    	@Autowired
    	private RestTemplate restTpl;
    
    	@HystrixCommand(fallbackMethod = "getMemberFallback", groupKey = "MemberGroup", commandKey = "MemberCommandKey",
    			commandProperties = {
    			@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000")
    	}, threadPoolProperties = {
    			@HystrixProperty(name = "coreSize", value = "2")
    	})
    	public Member getMember(Integer id) {
    		try {
    			Thread.sleep(2000);
    		} catch (Exception e) {
    			
    		}
    		
    		Member member = restTpl.getForObject(
    				"http://spring-hy-member/member/{id}", Member.class, id);
    		return member;
    	}
    
    	public Member getMemberFallback(Integer id) {
    		Member m = new Member();
    		m.setId(1);
    		m.setName("error member");
    		return m;
    	}
    }
    

      

    @RestController
    public class TestController {
    
    	@Autowired
    	private MemberService memberService;
    
    	@RequestMapping(value = "/router", method = RequestMethod.GET, 
    			produces = MediaType.APPLICATION_JSON_VALUE)
    	public Member router() {
    		return memberService.getMember(1);
    	}
    
    }
    

      

  • 相关阅读:
    如何分析损益表
    如何修改windows 2008(R2)的远程桌面连接数
    08年Gartner商务智能平台魔法四分区
    浅谈BI项目——为失败BI项目解惑(转IT168)
    商业智能项目错误经验总结(三) 需求调研
    asp.net学习笔记·Cookie
    C#安全调用线程的步骤
    一般处理程序学习初步——最简单的一般处理程序
    asp.net学习笔记·get与post区别
    C#中使用DES和AES加密解密
  • 原文地址:https://www.cnblogs.com/zfzf1/p/8550521.html
Copyright © 2011-2022 走看看