Spring Hystrix熔斷報(bào)警原理圖例解析
Hystrix 是一個(gè)幫助解決分布式系統(tǒng)交互時(shí)超時(shí)處理和容錯(cuò)的類(lèi)庫(kù), 它同樣擁有保護(hù)系統(tǒng)的能力。Netflix的眾多開(kāi)源項(xiàng)目之一。
設(shè)計(jì)流程:
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ā)送一個(gè)http請(qǐng)求,請(qǐng)求短信服務(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','搶購(gòu)人數(shù)太多,請(qǐng)稍后再試'); return msg; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 利用promise及參數(shù)解構(gòu)封裝ajax請(qǐng)求的方法2. Nginx+php配置文件及原理解析3. windows服務(wù)器使用IIS時(shí)thinkphp搜索中文無(wú)效問(wèn)題4. .NET中l(wèi)ambda表達(dá)式合并問(wèn)題及解決方法5. JSP數(shù)據(jù)交互實(shí)現(xiàn)過(guò)程解析6. 淺談python出錯(cuò)時(shí)traceback的解讀7. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解8. Ajax實(shí)現(xiàn)表格中信息不刷新頁(yè)面進(jìn)行更新數(shù)據(jù)9. Python importlib動(dòng)態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼10. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向
