Spring Hystrix熔斷報警原理圖例解析
Hystrix 是一個幫助解決分布式系統(tǒng)交互時超時處理和容錯的類庫, 它同樣擁有保護系統(tǒng)的能力。Netflix的眾多開源項目之一。
設(shè)計流程:
1.加入Redis依賴
<!--springboot整合redis--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
2.配置Redis信息:
spring: application: name: order-service redis: database: 0 host: 127.0.0.1 port: 6379 timeout: 2000
3.
//注意:方法名稱一定要與api方法一致 private Object saveOrderFail(Integer userId,Integer productId){ String saveOrderKey = 'save-order'; String sendValue = (String) redisTemplate.opsForValue().get(saveOrderKey); new Thread( () ->{ if (StringUtils.isBlank(sendValue)){//發(fā)送一個http請求,請求短信服務(wù)redisTemplate.opsForValue().set(saveOrderKey,'save-order-fail',20, TimeUnit.SECONDS); } }).start(); Map<String, Object> msg= new HashMap<>(); msg.put('code',-1); msg.put('msg','搶購人數(shù)太多,請稍后再試'); return msg; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. jsp+mysql實現(xiàn)網(wǎng)頁的分頁查詢2. 關(guān)于HTML的語義化標(biāo)簽和無語義化標(biāo)簽3. Java 抽象類與接口的對比4. Spring中基于xml的AOP的詳細步驟5. 最新IDEA快速實現(xiàn)Docker鏡像部署運行的過程詳解6. python os.listdir()亂碼解決方案7. 利用CSS3新特性創(chuàng)建透明邊框三角8. python 實用工具狀態(tài)機transitions9. HTML中l(wèi)ink標(biāo)簽屬性詳解10. div的offsetLeft與style.left區(qū)別
