PatientController.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 com.yihu.jw.version.ApiVersion;
  6. import io.swagger.annotations.Api;
  7. import io.swagger.annotations.ApiOperation;
  8. import io.swagger.annotations.ApiParam;
  9. import org.slf4j.Logger;
  10. import org.slf4j.LoggerFactory;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.beans.factory.annotation.Value;
  13. import org.springframework.cloud.context.config.annotation.RefreshScope;
  14. import org.springframework.cloud.sleuth.Tracer;
  15. import org.springframework.http.ResponseEntity;
  16. import org.springframework.web.bind.annotation.*;
  17. import org.springframework.web.client.RestTemplate;
  18. import org.springframework.web.context.annotation.SessionScope;
  19. import javax.servlet.http.HttpServletRequest;
  20. /**
  21. * Created by chenweida on 2017/5/10.
  22. */
  23. @RestController
  24. @RequestMapping("/{version}/patient")
  25. @Api(description = "患者")
  26. public class PatientController {
  27. private Logger logger= LoggerFactory.getLogger(PatientController.class);
  28. @Autowired
  29. private PatientFegin patientFegin;
  30. @Autowired
  31. private Tracer tracer;
  32. @ApiOperation(value = "根据code查找患者")
  33. @GetMapping(value = "findByCode")
  34. //配置HystrixProperty 则调用的方法和fallback是同一个线程 否则就不是
  35. //@HystrixCommand(fallbackMethod = "findByCodeFallback",commandProperties = @HystrixProperty(name = "execution.isolation.strategy",value = "SEMAPHORE"))
  36. // @HystrixCommand(fallbackMethod = "findByCodeFallback" )
  37. @HystrixCommand(commandProperties = {
  38. @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
  39. @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
  40. public String findByCode(
  41. @ApiParam(name = "code", value = "患者code", required = true) @RequestParam(value = "code", required = true) String code) {
  42. tracer.getCurrentSpan().logEvent("开始调用微服务查询患者");
  43. String text1 =patientFegin.findByCode(code);
  44. tracer.getCurrentSpan().logEvent("查询调用微服务找患者结束");
  45. return text1;
  46. }
  47. // /**
  48. // * 参数要一致 返回值类型也要一致
  49. // *
  50. // * @param code
  51. // * @return
  52. // */
  53. // public String findByCodeFallback(String code) {
  54. // return "启动断路器";
  55. // }
  56. @GetMapping("/hello")
  57. @ApiVersion(1)
  58. @ResponseBody
  59. public String hello1(HttpServletRequest request){
  60. System.out.println("haha1..........");
  61. return "hello";
  62. }
  63. @GetMapping("/hello")
  64. @ApiVersion(2)
  65. @ResponseBody
  66. public String hello2(HttpServletRequest request){
  67. System.out.println("haha2.........");
  68. return "hello";
  69. }
  70. }