まず第一に、ここでの再試行はエラーが報告された後は再試行ではありませんが、ロードバランシングクライアントがリモートリクエストインスタンスが利用できないことを発見した後、別のインスタンスに再試行します。
@bean@loadbalendresttemplate resttemplate(){httpcomponentsclienthtprequestfactory httprequestfactory = new httpcomponentsclienthtprequestfactory(); httprequestFactory.setReadTimeout(5000); httprequestFactory.setConnectTimeout(5000);新しいRESTTEMPLATE(httpRequestFactory);}偽りの再試行メカニズム
Feignは、それ自体でパッケージ化されたRetryerを介して構成を再試行し、デフォルトは5回です
パッケージfeign; static java.util.concurrent.timeunit.seconds;/*** {@link client#execute(requign.request.options)}への呼び出しごとにクローン化されます。 *実装は、再試行操作が継続するかどうかを判断するために状態を維持する場合があります。 * /public Interface Retryerはクローン可能{ /*** retryが許可されている場合(おそらく睡眠後)retunable { /***拡張します。それ以外の場合は、例外を伝播します。 */ void continueorpropagate(retryableException e); retryer clone(); public static classデフォルトの実装retryer {private final int maxattempts;プライベートな最終長い期間。プライベートファイナルロングマックス周辺。 int試行;長い眠り。 public default(){this(100、seconds.tomillis(1)、5); } public default(long period、long maxperiod、int maxattempts){this.period = period; this.maxperiod = maxperiod; this.maxattempts = maxattempts; this.attemp = 1; } feign CANCEL RETRY
@bean retryer feignretryer(){return retryer.never_retry; }プリグインリクエストタイムアウト設定
@beanRequest.options requestoptions(configureableenvironment env){int ribbonedtimeout = env.getProperty( "ribbon.readtimeout"、int.class、6000); int ribbonconnectiontimeout = env.getProperty( "ribbon.connecttimeout"、int.class、3000); new request.options(ribbonconnectiontimeout、ribbonreadtimeout);}上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。