openfeign 负载均衡调用服务
生活随笔
收集整理的這篇文章主要介紹了
openfeign 负载均衡调用服务
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://github.com/spring-cloud/spring-cloud-openfeign
openFeign, fegin 👆
- open fegin
- openFegin使用
- 日志打印配置類
open fegin
openFegin使用
pom
<!-- open-feign demo, based on client~ and get a ribbon~ --><!--https://github.com/spring-cloud/spring-cloud-openfeign--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency>yaml
超時控制和日志記錄
主啟動
@EnableFeignClients服務接口, 調用服務提供者
package top.bitqian.springcloud.service;import org.springframework.cloud.openfeign.FeignClient; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import top.bitqian.springcloud.entity.CommonResult; import top.bitqian.springcloud.entity.Payment;/*** 業務層 feign~* 需要feignClient 和 服務提供者的接口* restTemplate + ribbon 是一套~* @author echo lovely* @date 2020/12/8 22:02*/// 被調用的微服務名稱 @FeignClient(value = "CLOUD-PAYMENT-SERVICE") @Component public interface PaymentFeignService {@GetMapping("/payment/get/{id}")CommonResult<Payment> getPaymentById(@PathVariable("id") Long id);// 模擬某個業務進行,調用feign接口@GetMapping("/payment/feign/timeout")String paymentFeignTimeout(); }日志打印配置類
package top.bitqian.springcloud.config;import feign.Logger; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;/*** 記錄調用服務端的日志* 通過調整日志級別,從而了解Feign中的http請求細節* 對feign接口調用情況,進行監控和輸出~* None 默認的不顯示任何日志* BASIC 僅記錄請求方法,url,響應狀態碼,及執行時間* HEADERS basic 請求響應的頭信息* FULL headers 請求響應的正文,數據* @author echo lovely* @date 2020/12/9 22:26*/@Configuration public class FeignConfig {// 響應,請求信息~@BeanLogger.Level feignLoggerLevel() {return Logger.Level.FULL;} }總結
以上是生活随笔為你收集整理的openfeign 负载均衡调用服务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python自动登录教程_Python
- 下一篇: java 实现word转txt