PatientController.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.cloud.sleuth.Tracer;
  14. import org.springframework.http.ResponseEntity;
  15. import org.springframework.web.bind.annotation.*;
  16. import org.springframework.web.client.RestTemplate;
  17. import org.springframework.web.context.annotation.SessionScope;
  18. /**
  19. * Created by chenweida on 2017/5/10.
  20. */
  21. @RestController
  22. @RequestMapping("/rest/patient")
  23. @Api(description = "患者")
  24. public class PatientController {
  25. private Logger logger= LoggerFactory.getLogger(PatientController.class);
  26. @Autowired
  27. private PatientFegin patientFegin;
  28. @Autowired
  29. private Tracer tracer;
  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. tracer.getCurrentSpan().logEvent("开始调用微服务查询患者");
  41. String text1 =patientFegin.findByCode(code);
  42. tracer.getCurrentSpan().logEvent("查询调用微服务找患者结束");
  43. return text1;
  44. }
  45. // /**
  46. // * 参数要一致 返回值类型也要一致
  47. // *
  48. // * @param code
  49. // * @return
  50. // */
  51. // public String findByCodeFallback(String code) {
  52. // return "启动断路器";
  53. // }
  54. }