PatientController.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package com.yihu.jw.controller;
  2. import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
  3. import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
  4. import com.yihu.jw.fegin.PatientFegin;
  5. import io.swagger.annotations.Api;
  6. import io.swagger.annotations.ApiOperation;
  7. import io.swagger.annotations.ApiParam;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.beans.factory.annotation.Value;
  12. import org.springframework.cloud.context.config.annotation.RefreshScope;
  13. import org.springframework.http.ResponseEntity;
  14. import org.springframework.web.bind.annotation.*;
  15. import org.springframework.web.client.RestTemplate;
  16. import org.springframework.web.context.annotation.SessionScope;
  17. /**
  18. * Created by chenweida on 2017/5/10.
  19. */
  20. @RestController
  21. @RequestMapping("/rest/patient")
  22. @Api(description = "患者")
  23. @RefreshScope
  24. public class PatientController {
  25. private Logger logger= LoggerFactory.getLogger(PatientController.class);
  26. @Autowired
  27. private PatientFegin patientFegin;
  28. @Value("${test}")
  29. private String test;
  30. @ApiOperation(value = "根据code查找患者")
  31. @GetMapping(value = "findByCode")
  32. //配置HystrixProperty 则调用的方法和fallback是同一个线程 否则就不是
  33. //@HystrixCommand(fallbackMethod = "findByCodeFallback",commandProperties = @HystrixProperty(name = "execution.isolation.strategy",value = "SEMAPHORE"))
  34. // @HystrixCommand(fallbackMethod = "findByCodeFallback" )
  35. @HystrixCommand(commandProperties = {
  36. @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
  37. @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
  38. public String findByCode(
  39. @ApiParam(name = "code", value = "患者code", required = true) @RequestParam(value = "code", required = true) String code) {
  40. logger.info("start");
  41. String text1 =patientFegin.findByCode(code);
  42. logger.info("text");
  43. String text2 =patientFegin.findByCode(code);
  44. return text1+text2;
  45. }
  46. @ApiOperation(value = "测试配置刷新")
  47. @GetMapping(value = "test")
  48. public String test() {
  49. return test;
  50. }
  51. // /**
  52. // * 参数要一致 返回值类型也要一致
  53. // *
  54. // * @param code
  55. // * @return
  56. // */
  57. // public String findByCodeFallback(String code) {
  58. // return "启动断路器";
  59. // }
  60. }