PatientController.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.http.ResponseEntity;
  12. import org.springframework.web.bind.annotation.*;
  13. import org.springframework.web.client.RestTemplate;
  14. import org.springframework.web.context.annotation.SessionScope;
  15. /**
  16. * Created by chenweida on 2017/5/10.
  17. */
  18. @RestController
  19. @RequestMapping("/rest/patient")
  20. @Api(description = "患者")
  21. public class PatientController {
  22. private Logger logger= LoggerFactory.getLogger(PatientController.class);
  23. @Autowired
  24. private PatientFegin patientFegin;
  25. @ApiOperation(value = "根据code查找患者")
  26. @GetMapping(value = "findByCode")
  27. //配置HystrixProperty 则调用的方法和fallback是同一个线程 否则就不是
  28. //@HystrixCommand(fallbackMethod = "findByCodeFallback",commandProperties = @HystrixProperty(name = "execution.isolation.strategy",value = "SEMAPHORE"))
  29. // @HystrixCommand(fallbackMethod = "findByCodeFallback" )
  30. @HystrixCommand(commandProperties = {
  31. @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
  32. @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
  33. public String findByCode(
  34. @ApiParam(name = "code", value = "患者code", required = true) @RequestParam(value = "code", required = true) String code) {
  35. logger.info("start");
  36. String text1 =patientFegin.findByCode(code);
  37. logger.info("text");
  38. String text2 =patientFegin.findByCode(code);
  39. return text1+text2;
  40. }
  41. // /**
  42. // * 参数要一致 返回值类型也要一致
  43. // *
  44. // * @param code
  45. // * @return
  46. // */
  47. // public String findByCodeFallback(String code) {
  48. // return "启动断路器";
  49. // }
  50. }