最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用feign配置網(wǎng)絡(luò)ip代理

 更新時(shí)間:2022年06月30日 08:40:06   作者:coder@  
這篇文章主要介紹了使用feign配置網(wǎng)絡(luò)ip代理,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

feign配置網(wǎng)絡(luò)ip代理

問(wèn)題描述

測(cè)試環(huán)境將需要訪問(wèn)的外網(wǎng)地址加入了白名單,但是docker和宿主機(jī)網(wǎng)絡(luò)不一樣(試過(guò)掛載宿主機(jī)網(wǎng)絡(luò)也不行,但是掛載宿主機(jī)網(wǎng)絡(luò)會(huì)打亂原有的網(wǎng)絡(luò)環(huán)境),所以造成了在宿主機(jī)上面可以訪問(wèn)該地址,但是docker里面是訪問(wèn)不到外網(wǎng)的地址,所使用feign的時(shí)候加上ip代理,代理宿主機(jī)ip來(lái)對(duì)外網(wǎng)地址進(jìn)行訪問(wèn)!

為什么不直接對(duì)docker設(shè)置網(wǎng)絡(luò)代理,測(cè)試環(huán)境里面基本都是內(nèi)部服務(wù)調(diào)用,如果設(shè)置則會(huì)導(dǎo)致其網(wǎng)絡(luò)不一致,并且開發(fā)測(cè)試正式環(huán)境較為復(fù)雜,如果不需要的時(shí)候直接在配置文件配置為null就行

1.依賴

<dependency>
? ? <groupId>org.apache.httpcomponents</groupId>
? ? <artifactId>httpclient</artifactId>
? ? <version>4.5.10</version>
</dependency>
<dependency>
? ? ?<groupId>io.github.openfeign</groupId>
? ? ? <artifactId>feign-okhttp</artifactId>
</dependency>
//可能還需要feign相關(guān)依賴 feign-okhttp主要用來(lái)做網(wǎng)絡(luò)代理,依賴需要自行百度

2.feignclinet接口

import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
/**
?* @ClassName?
?* @Description url遠(yuǎn)程調(diào)用的url
?* @Author liuf
?* @Date 2021/10/29 16:19
?* @Version 1.0
?**/
@FeignClient(url = "http://xxx.xxx.xxx.xxx:8090" ,name = "slmodel-one")
public interface SlModelOneClient {
? ? @ApiOperation("XXXXXXX")
? ? @RequestMapping(
? ? ? ? ? ? method = RequestMethod.GET,
? ? ? ? ? ? value = "/efdcserver/efdcserver/getEfdcCodeByProjectName",
? ? ? ? ? ? consumes = "application/json;charset=UTF-8",
? ? ? ? ? ? produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
? ? List<JsonAreaCode> getEfdcCodeByProjectName(
? ? ? ? ? ? @RequestParam("projectName") String projectName);
? ? @ApiOperation("XXXXXXX")
? ? @RequestMapping(
? ? ? ? ? ? method = RequestMethod.POST,
? ? ? ? ? ? value = "/efdcserver/hydro/getDepthMapByPost?efdcCode={efdcCode}&planName={planName}",
? ? ? ? ? ? consumes = "application/json;charset=UTF-8",
? ? ? ? ? ? produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
? ? DepthMap getDepthMapByPost(
? ? ? ? ? ? @PathVariable(name="efdcCode") String efdcCode,
? ? ? ? ? ? @PathVariable(name ="planName")String planName);
? ? @ApiOperation("XXXXXXX")
? ? @RequestMapping(
? ? ? ? ? ? method = RequestMethod.GET,
? ? ? ? ? ? value = "/efdcserver/hydro/getPoint?planName={planName}&efdcCode={efdcCode}&lgtd={lgtd}&lttd={lttd}",
? ? ? ? ? ? consumes = "application/json;charset=UTF-8",
? ? ? ? ? ? produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
? ? DepthMap getPointDepthByGet(
? ? ? ? ? ? @PathVariable(name ="planName")String planName,
? ? ? ? ? ? @PathVariable(name="efdcCode") String efdcCode ,
? ? ? ? ? ? @PathVariable(name ="lotd")Double lgtd,
? ? ? ? ? ? @PathVariable(name ="lttd")Double lttd);
}

3.Config

import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.commons.httpclient.DefaultOkHttpClientFactory;
import org.springframework.cloud.commons.httpclient.OkHttpClientFactory;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.io.IOException;
import java.net.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
?* @Description: feign代理設(shè)置
?* @Author: liuf
?* @Date:
?* @Param:
?* @Return:
?**/
@Configuration
@EnableFeignClients(basePackages = "com.ceshi..map.client")
public class Config {
? ? @Value("${proxy.host}")
? ? private String proxyHost;
? ? @Value("${proxy.port}")
? ? private Integer proxyPort;
? ? @Value("#{'${proxy.domains}'.split(',')}")
? ? private Set<String> domainList;
? ? @Bean
? ? public OkHttpClientFactory okHttpClientFactory(OkHttpClient.Builder builder) {
? ? ? ? return new ProxyOkHttpClientFactory(builder);
? ? }
? ? class ProxyOkHttpClientFactory extends DefaultOkHttpClientFactory {
? ? ? ? public ProxyOkHttpClientFactory(OkHttpClient.Builder builder) {
? ? ? ? ? ? super(builder);
? ? ? ? ? ? //如果配置文件中的代理信息為null 則該代理ip配置不生效
? ? ? ? ? ? if(proxyHost!=null&&proxyPort!=null&&domainList!=null) {
? ? ? ? ? ? ? ? Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
? ? ? ? ? ? ? ? List<Proxy> proxyList = new ArrayList<>(1);
? ? ? ? ? ? ? ? proxyList.add(proxy);
? ? ? ? ? ? ? ? builder.proxySelector(new ProxySelector() {
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public List<Proxy> select(URI uri) {
? ? ? ? ? ? ? ? ? ? ? ? if (uri == null || !domainList.contains(uri.getHost())) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? return Collections.singletonList(Proxy.NO_PROXY);
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? return proxyList;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? }
? ? }
}

4.yml

使用IP代理

feign:
?okhttp:
? enabled: true
proxy:
?host: 199.168.233.32 //需要代理的ip
?port: 4444
?domains: 222.222.231.116,222.222.231.117 //需要訪問(wèn)的地址 host 如果多個(gè) 用逗號(hào)分割

不使用IP代理

feign:
?okhttp:
? enabled: true
proxy:
?host: null
?port: null
?domains: null

調(diào)用指定ip的feign接口

@FeignClient(value = “center-educational-server”,url=“http://127.0.0.1:10005”)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • java中ExecutorService創(chuàng)建方法總結(jié)

    java中ExecutorService創(chuàng)建方法總結(jié)

    在本篇文章里小編給大家整理了一篇關(guān)于java中ExecutorService創(chuàng)建方法總結(jié),有興趣的朋友們可以參考下。
    2021-01-01
  • 如何使用Spring自定義Xml標(biāo)簽

    如何使用Spring自定義Xml標(biāo)簽

    要實(shí)現(xiàn)自定義的xml配置,需要有兩個(gè)默認(rèn)spring配置文件來(lái)支持。一個(gè)是spring.schemas,一個(gè)是spring.handlers,前者是為了驗(yàn)證你自定義的xml配置文件是否符合你的格式要求,后者是告訴spring該如何來(lái)解析你自定義的配置文件。本文將介紹如何使用Spring自定義Xml標(biāo)簽
    2021-06-06
  • Java并發(fā)線程之線程池的知識(shí)總結(jié)

    Java并發(fā)線程之線程池的知識(shí)總結(jié)

    這篇文章主要介紹了Java并發(fā)線程之線程池的知識(shí)總結(jié),幫助大家更好的理解和學(xué)習(xí)Java并發(fā)線程的相關(guān)內(nèi)容,感興趣的朋友可以了解下
    2021-01-01
  • 使用Spring初始化加載InitializingBean()方法

    使用Spring初始化加載InitializingBean()方法

    這篇文章主要介紹了使用Spring初始化加載InitializingBean()方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-01-01
  • springboot aop添加日志方式

    springboot aop添加日志方式

    這篇文章主要介紹了springboot aop添加日志方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • 詳解堆排序算法原理及Java版的代碼實(shí)現(xiàn)

    詳解堆排序算法原理及Java版的代碼實(shí)現(xiàn)

    如果將堆理解為二叉樹,那么樹中任一非葉結(jié)點(diǎn)的關(guān)鍵字均不大于(或不小于)其左右孩子(若存在)結(jié)點(diǎn)的關(guān)鍵字,堆排序的時(shí)間復(fù)雜度為O(N*logN),這里我們就來(lái)詳解堆排序算法原理及Java版的代碼實(shí)現(xiàn)
    2016-06-06
  • SpringBoot讀取properties中文亂碼解決方案

    SpringBoot讀取properties中文亂碼解決方案

    本文主要介紹了在Spring?Boot中讀取帶有中文字符串的application.properties文件時(shí)遇到亂碼問(wèn)題的解決方案,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-12-12
  • springboot?vue測(cè)試平臺(tái)接口定義前后端新增功能實(shí)現(xiàn)

    springboot?vue測(cè)試平臺(tái)接口定義前后端新增功能實(shí)現(xiàn)

    這篇文章主要介紹了springboot?vue測(cè)試平臺(tái)接口定義前后端新增功能實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • 基于SpringCloudAlibaba+Skywalking的全鏈路監(jiān)控設(shè)計(jì)方案

    基于SpringCloudAlibaba+Skywalking的全鏈路監(jiān)控設(shè)計(jì)方案

    這篇文章主要介紹了基于SpringCloudAlibaba+Skywalking的全鏈路監(jiān)控設(shè)計(jì)方案,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2024-01-01
  • Java?for循環(huán)倒序輸出的操作代碼

    Java?for循環(huán)倒序輸出的操作代碼

    在Java中,要實(shí)現(xiàn)一個(gè)for循環(huán)的倒序輸出,通常我們會(huì)使用數(shù)組或集合(如ArrayList)作為數(shù)據(jù)源,然后通過(guò)倒序遍歷這個(gè)數(shù)組或集合來(lái)實(shí)現(xiàn),這篇文章主要介紹了Java?for循環(huán)倒序輸出,需要的朋友可以參考下
    2024-07-07

最新評(píng)論

报价| 彭泽县| 新晃| 宕昌县| 英山县| 图片| 波密县| 本溪市| 深泽县| 榆中县| 永和县| 彩票| 观塘区| 昔阳县| 岳普湖县| 谷城县| 龙门县| 雅江县| 萨迦县| 安康市| 高唐县| 新沂市| 靖宇县| 凉山| 霍城县| 比如县| 松潘县| 肇庆市| 安远县| 澄江县| 田阳县| 内黄县| 淮安市| 华阴市| 湖北省| 长治县| 通化县| 资溪县| 什邡市| 会泽县| 普兰县|