In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the principle and function of Targeter in spring cloud openfeign". In daily operation, I believe that many people have doubts about the principle and function of Targeter in spring cloud openfeign. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what is the principle and function of Targeter in spring cloud openfeign?" Next, please follow the editor to study!
Order
This paper mainly studies the Targeter of spring cloud openfeign.
Targeter
Springhouse cloudlyopenfeignMutel coreMuray 2.2.0.M1ripsources.jarroomUniverse orgAccording frameworkhand cloudhand openfeignUniverse Targeter.java
Interface Targeter {T target (FeignClientFactoryBean factory, Feign.Builder feign, FeignContext context, Target.HardCodedTarget target);}
Targeter defines the target method, which receives parameters of types FeignClientFactoryBean, Feign.Builder, FeignContext, and Target.HardCodedTarget.
DefaultTargeter
Springhouse cloudhouse openfeignhouse coreMuray 2.2.0.M1ripsources.jarroomUniverse orgAccording frameworkhand cloudhand openfeignhand DefaultTargeter.java
Class DefaultTargeter implements Targeter {@ Override public T target (FeignClientFactoryBean factory, Feign.Builder feign, FeignContext context, Target.HardCodedTarget target) {return feign.target (target);}}
DefaultTargeter implements the Targeter interface, and its target method directly uses the Feign.Builder.target method
Target
FeignMuscoreMushue 10.2.3Mutual sources.jarhammer Universe feignripple Target.java
Public interface Target {/ * The type of the interface this target applies to. Ex. {@ code Route53}. * / Class type (); / * configuration key associated with this target. For example, {@ code route53}. * / String name (); / * base HTTP URL of the target. For example, {@ code https://api/v2}. * / String url (); public Request apply (RequestTemplate input); / /.}
The Target interface defines type, name, url, apply methods.
HardCodedTarget
FeignMuscoreMushue 10.2.3Mutual sources.jarhammer Universe feignripple Target.java
Public static class HardCodedTarget implements Target {private final Class type; private final String name; private final String url; public HardCodedTarget (Class type, String url) {this (type, url, url);} public HardCodedTarget (Class type, String name, String url) {this.type = checkNotNull (type, "type"); this.name = checkNotNull (emptyToNull (name), "name"); this.url = checkNotNull (emptyToNull (url), "url") @ Override public Class type () {return type;} @ Override public String name () {return name;} @ Override public String url () {return url;} / * no authentication or other special activity. Just insert the url. * / @ Override public Request apply (RequestTemplate input) {if (input.url (). IndexOf ("http")! = 0) {input.target (url ());} return input.request ();} @ Override public boolean equals (Object obj) {if (obj instanceof HardCodedTarget) {HardCodedTarget other = (HardCodedTarget) obj Return type.equals (other.type) & & name.equals (other.name) & & url.equals (other.url);} return false;} @ Override public int hashCode () {int result = 17; result = 31 * result + type.hashCode (); result = 31 * result + name.hashCode (); result = 31 * result + url.hashCode (); return result } @ Override public String toString () {if (name.equals (url)) {return "HardCodedTarget (type=" + type.getSimpleName () + ", url=" + url + ")";} return "HardCodedTarget (type=" + type.getSimpleName () + ", name=" + name + ", url=" + url + ")";}}
HardCodedTarget implements the Target interface, and its constructor receives type, name, and url parameters. Its apply method sets the target of RequestTemplate to url if url begins with http, and then constructs request to return
HystrixTargeter
Springhouse cloudlyopenfeignMuscoreMurray 2.2.0.M1ripsources.jarroomUniverse orgAccording frameworkhand cloudhand openfeignhand HystrixTargeter.java
Class HystrixTargeter implements Targeter {@ Override public T target (FeignClientFactoryBean factory, Feign.Builder feign, FeignContext context, Target.HardCodedTarget target) {if (! (feign instanceof feign.hystrix.HystrixFeign.Builder)) {return feign.target (target);} feign.hystrix.HystrixFeign.Builder builder = (feign.hystrix.HystrixFeign.Builder) feign SetterFactory setterFactory = getOptional (factory.getName (), context, SetterFactory.class); if (setterFactory! = null) {builder.setterFactory (setterFactory);} Class fallback = factory.getFallback () If (fallback! = void.class) {return targetWithFallback (factory.getName (), context, target, builder, fallback);} Class fallbackFactory = factory.getFallbackFactory () If (fallbackFactory! = void.class) {return targetWithFallbackFactory (factory.getName (), context, target, builder, fallbackFactory);} return feign.target (target) } private T targetWithFallbackFactory (String feignClientName, FeignContext context, Target.HardCodedTarget target, HystrixFeign.Builder builder, Class fallbackFactoryClass) {FallbackFactory
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.