1. 程式人生 > 其它 >遍歷物件鍵值對的四種方法

遍歷物件鍵值對的四種方法

技術標籤:java

OpenFeign簡介

與dubbo相似,可通過消費者controller呼叫提供者service層方法。
與之不同的是,OpenFeign只能呼叫提供者的controller,即,將controller作為介面,消費者來呼叫這個介面的方法。
相當於呼叫提供者的controller,與RestTemplate沒有本質區別

Feign作用
Feign中集成了Ribbon,並在Ribbon+Rest
Template的基礎上進一步封裝。(只需建立一個介面並使用註解的方式來配置)簡化了使用SpringcloudRibbon時,自動封裝服務呼叫客戶端的開發量。
Feign利用Ribbon維護了Payment的服務列表資訊,並通過輪詢實現了客戶端的負載均衡。

但,與Ribbon區別是,feign只需定義服務繫結介面且以宣告式的方法,更簡單的實現了服務呼叫。
Feign自帶負載均衡配置,不用手動配置。
專案測試:
建立消費者模組:cloud-consumer-feign-order80 pom.xml檔案中新增依賴

org.springframework.cloud spring-cloud-starter-openfeign org.springframework.cloud spring-cloud-starter-netflix-eureka-client com.usan.commons cloud-api-commons ${project.version} org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-actuator org.projectlombok lombok true org.springframework.boot spring-boot-devtools runtime true org.springframework.boot spring-boot-starter-test test 編寫yml配置檔案 server: port: 80 spring: application: name: cloud-consumer-feign-service eureka: client: register-with-eureka: true fetch-registry: true service-url: defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eur 編寫啟動類 @SpringBootApplication @EnableFeignClients // 開啟使用feign客戶端功能 public class CustomerFeignMain80 { public static void main(String[] args) { SpringApplication.run(CustomerFeignMain80.class, args); } } 編寫feign客戶端 // 標識當前介面是一個feign客戶端,並且指定呼叫哪一個微服務 @FeignClient(value = "cloud-payment-service") public interface PaymentFeignService {
@GetMapping("payment/{id}")
CommonResult<Payment> getPaymentById(@PathVariable("id") Long id);

}
啟動測試
需要啟動 eureka7001,7002、服務提供方 8001 8002在這裡插入圖片描述