日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Cloud【Finchley】-09Feign使用Hystrix

發(fā)布時(shí)間:2025/3/21 javascript 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Cloud【Finchley】-09Feign使用Hystrix 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

  • 版本說明
  • 新建子module
  • application.yml中開啟Hystrix
  • 修改Feign接口
  • 測(cè)試
  • 代碼

版本說明

先說下使用的spring cloud和spring boot的版本

Disable HystrixCommands For FeignClients By Default
https://github.com/spring-cloud/spring-cloud-netflix/issues/1277


新建子module

父工程microservice-spring-cloud右鍵新建Maven Module 命名為:micorservice-consumer-movie-feign-hystrix ,為了簡單我們把micorservice-consumer-movie-feign的內(nèi)容copy到該子模塊,修改下application.yml中的spring.application.name即可。


application.yml中開啟Hystrix

server:port: 7901spring: application:name: micorservice-consumer-movie-feign-hystrix #eureka eureka: client:service-url:defaultZone: http://artisan:artisan123@localhost:8761/eurekainstance:prefer-ip-address: trueinstance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}# Disable HystrixCommands For FeignClients By Default # https://github.com/spring-cloud/spring-cloud-netflix/issues/1277 feign:hystrix:enabled: true

如果是application.property ,請(qǐng)?jiān)O(shè)置 feign.hystrix.enabled=true


修改Feign接口

使用fallback屬性指定回退類

回退類 也需要實(shí)現(xiàn)上面的接口,同時(shí)需要標(biāo)注@Component讓其成為受spring管理的bean


測(cè)試

  • 啟動(dòng)microservice-discovery-eureka,注冊(cè)中心
  • 啟動(dòng)micorservice-provider-user,服務(wù)提供者
  • 啟動(dòng)micorservice-consumer-movie-feign-hystrix,服務(wù)消費(fèi)者開啟了Hystrix
  • 訪問http://localhost:8761/ 確認(rèn)下服務(wù)已經(jīng)注冊(cè)成功。

    訪問 http://localhost:7901/movie/1

    {"id":1,"username":"artisan1","name":"小工匠一","age":10,"balance":100.00}

    功能正常,OK。

    現(xiàn)在停掉micorservice-provider-user

    訪問 http://localhost:7901/movie/1 ,進(jìn)入了回退方法

    {"id":1,"username":"默認(rèn)用戶","name":null,"age":null,"balance":null}

    再次啟動(dòng) micorservice-provider-user

    再次訪問 http://localhost:7901/movie/1

    {"id":1,"username":"artisan1","name":"小工匠一","age":10,"balance":100.00}

    功能正常,OK。


    代碼

    https://github.com/yangshangwei/SpringCloudMaster/tree/master/micorservice-consumer-movie-fegin-hystrix

    總結(jié)

    以上是生活随笔為你收集整理的Spring Cloud【Finchley】-09Feign使用Hystrix的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。