Before downgrading of integration, based on the integration redis, achieve alarm (redis startup or boot inside before integration redis)
-
order-service
-
pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
-
application.yml
spring: application: name: order-service redis: port: 6379 host: 192.168.180.113 timeout: 2000
-
Modify the web layer, the add logic redis
1 @RestController 2 @RequestMapping("/api/v1/order") 3 public class OrderController { 4 5 6 @Autowired(required = false) 7 private ProductOrderServiceImpl productOrderService; 8 9 @Autowired 10 private StringRedisTemplate redisTemplate; 11 12 13 @RequestMapping("/save") 14 @HystrixCommand(fallbackMethod="saveOrderFail") 15 public Object save(@RequestParam("user_id")int userId, @RequestParam("product_id") int productId, HttpServletRequest request){ 16 17 Map<String, Object> data = new HashMap<>(); 18 data.put("code", 0); 19 data.put("data", productOrderService.save(userId, productId)); 20 return data; 21 } 22 23 24 //注意,方法签名一定要要和api方法一致 25 private Object saveOrderFail(int userId, int the productId, the HttpServletRequest Request) { 26 is 27 28 // monitoring alarm 29 String saveOrderKye = "Save-Order" ; 30 31 is String = sendValue . redisTemplate.opsForValue () GET (saveOrderKye); 32 Final String IP = Request. getRemoteAddr (); 33 is new new the Thread (() -> { 34 is IF (StringUtils.isBlank (sendValue)) { 35 System.out.println ( "urgent message, the subscriber unit fails, please leave find the cause, ip address =" + IP); 36 // send a http request, a short message service call the TODO 37 [ redisTemplate.opsForValue () SET (saveOrderKye, "Fail-Save-Order", 20 is. , TimeUnit.SECONDS); 38 is } the else { 39 System.out.println ( "has sent a message, the transmission will not be repeated within 20 seconds" ) ; 40 } 41 is 42 is .}) Start (); 43 is 44 is 45 the Map <String, Object> MSG = new new the HashMap <> (); 46 is msg.put ( "code", -1 ); 47 msg.put ( "msg", "number of people buying too much, you squeezed out, wait a retry" ); 48 return msg; 49 } 50 51 52 }
-
-
2019-10-19 20: 56: 11.880 INFO 20020 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty: Flipping property: product-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit 2147483647 = Feign call Product - -Service findById exception 2019-10-19 20 is: 56 is: 12.771 20020 --- the INFO [-HystrixTimer. 1 ] io.lettuce.core.EpollProvider: Starting the without the epoll optional Library 2019-10-19 20:56 : 12.774 20020 --- the INFO [-HystrixTimer. 1 ] io.lettuce.core.KqueueProvider: Starting the without the kqueue optional Library has sent a short message is not repeatedly transmitted within 20 seconds