<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 概述 Feign可以把Rest的請求進行隱藏,偽裝成類似SpringMVC的controller一樣.你不用再自己拼接url,拼接參數等等操作,一切都交給Feign去做.使用Feign會非常優雅.Feign自動實現了負載均衡. 可以看到feign自動引入了hystrix和ribbon,這兩個包都省的去引入了.使用feign負載均衡就不需要配置了,但是熔斷需要額外配置.并且跟之前的配置方式不一樣. ![](https://box.kancloud.cn/36ea21962f1f4cd0271b15d0b112b24b_1594x1078.png) ## feign的負載均衡 ~~~ ribbon: ConnectionTimeOut: 500 //連接超時(默認1秒),500毫秒沒有獲取連接就拋出異常 ReadTimeOut: 2000 //讀取超時(默認1秒),建立連接,但是超過2秒沒有讀取到數據也拋出異常 ~~~ ## 導包 ~~~ <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>2.0.1.RELEASE</version> </dependency> ~~~ ## 啟動類加注解 ~~~ package com.like; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.Bean; import org.springframework.web.client.RestTemplate; //@SpringBootApplication //@EnableDiscoveryClient //@EnableCircuitBreaker @EnableFeignClients //添加Feign客戶端注解 @SpringCloudApplication //可以使用該注解替代上面的三個注解 public class ConsumerServer { public static void main(String[] args) { SpringApplication.run(ConsumerServer.class); } @Bean @LoadBalanced public RestTemplate restTemplate() { return new RestTemplate(); } } ~~~ ## 編寫feign接口 ~~~ package com.like.client; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @FeignClient("user-server") //服務名稱 public interface UserClient { @GetMapping("/user/{id}") String queryById(@PathVariable("id") Long id); //方法名隨意 } ~~~ ## 調用接口 經測試,請求成功. ~~~ @RestController @RequestMapping("/user") @DefaultProperties(defaultFallback = "defaultCallBack") public class UserController { @Autowired private UserClient userClient; @GetMapping("/{id}") public String index(@PathVariable("id") Long id) { return userClient.queryById(id); } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看