本文整理汇总了Java中feign.hystrix.HystrixFeign类的典型用法代码示例。如果您正苦于以下问题:Java HystrixFeign类的具体用法?Java HystrixFeign怎么用?Java HystrixFeign使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HystrixFeign类属于feign.hystrix包,在下文中一共展示了HystrixFeign类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apiClient
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
@Produces
@Singleton
private ApiClient apiClient(Tracer tracer) {
String host = config.getValue(APIGATEWAY_URL, String.class);
String port = config.getValue(APIGATEWAY_PORT, String.class);
log.infof("API gateway expected at %s:%s", host, port);
return HystrixFeign.builder()
.client(new TracingClient(new ApacheHttpClient(HttpClientBuilder.create().build()), tracer))
.logger(new feign.Logger.ErrorLogger()).logLevel(feign.Logger.Level.BASIC)
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.target(ApiClient.class, String.format("http://%s:%s", host, port),
(LRA lra) -> rx.Observable.empty());
}
示例2: alohaService
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
/**
* This is were the "magic" happens: it creates a Feign, which is a proxy interface for remote calling a REST endpoint with
* Hystrix fallback support.
*
* @return The feign pointing to the service URL and with Hystrix fallback.
*/
@Produces
@Singleton
private AlohaService alohaService(Tracer tracer) {
// bind current span to Hystrix thread
TracingConcurrencyStrategy.register();
return HystrixFeign.builder()
// Use apache HttpClient which contains the ZipKin Interceptors
.client(new TracingClient(new ApacheHttpClient(HttpClientBuilder.create().build()), tracer))
// Bind Zipkin Server Span to Feign Thread
.logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC)
.decoder(new JacksonDecoder())
.target(AlohaService.class,"http://aloha:8080/",
() -> Collections.singletonList("Aloha response (fallback)"));
}
示例3: getNextService
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
/**
* This is were the "magic" happens: it creates a Feign, which is a proxy interface for remote calling a REST endpoint with
* Hystrix fallback support.
*
* @return The feign pointing to the service URL and with Hystrix fallback.
*/
private NamasteService getNextService() {
final String serviceName = "namaste";
// This stores the Original/Parent ServerSpan from ZiPkin.
final ServerSpan serverSpan = brave.serverSpanThreadBinder().getCurrentServerSpan();
final CloseableHttpClient httpclient =
HttpClients.custom()
.addInterceptorFirst(new BraveHttpRequestInterceptor(brave.clientRequestInterceptor(), new DefaultSpanNameProvider()))
.addInterceptorFirst(new BraveHttpResponseInterceptor(brave.clientResponseInterceptor()))
.build();
String url = String.format("http://%s:8080/", serviceName);
return HystrixFeign.builder()
// Use apache HttpClient which contains the ZipKin Interceptors
.client(new ApacheHttpClient(httpclient))
// Bind Zipkin Server Span to Feign Thread
.requestInterceptor((t) -> brave.serverSpanThreadBinder().setCurrentSpan(serverSpan))
.logger(new Logger.ErrorLogger()).logLevel(Level.BASIC)
.decoder(new JacksonDecoder())
.target(NamasteService.class, url,
() -> Collections.singletonList("Namaste response (fallback)"));
}
示例4: publish
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
@Asynchronous
public void publish(final Event event) {
if (BASE_URL == null || BASE_URL.isEmpty()) {
logger.hawkularServerNotConfigured();
return;
}
if (USERNAME == null || USERNAME.isEmpty()) {
logger.hawkularServerUsernameNotConfigured();
return;
}
if (PASSWORD == null || PASSWORD.isEmpty()) {
logger.hawkularServerPasswordNotConfigured();
return;
}
HystrixFeign.builder()
.requestInterceptor(new BasicAuthRequestInterceptor(USERNAME, PASSWORD))
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.retryer(new Retryer.Default())
.target(AlertsService.class, TARGET)
.addEvent(event);
}
示例5: targetWithFallbackFactory
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
private <T> T targetWithFallbackFactory(String feignClientName, FeignContext context,
Target.HardCodedTarget<T> target,
HystrixFeign.Builder builder,
Class<?> fallbackFactoryClass) {
FallbackFactory<? extends T> fallbackFactory = (FallbackFactory<? extends T>)
getFromContext("fallbackFactory", feignClientName, context, fallbackFactoryClass, FallbackFactory.class);
/* We take a sample fallback from the fallback factory to check if it returns a fallback
that is compatible with the annotated feign interface. */
Object exampleFallback = fallbackFactory.create(new RuntimeException());
Assert.notNull(exampleFallback,
String.format(
"Incompatible fallbackFactory instance for feign client %s. Factory may not produce null!",
feignClientName));
/*if (!target.type().isAssignableFrom(exampleFallback.getClass())) {
throw new IllegalStateException(
String.format(
"Incompatible fallbackFactory instance for feign client %s. Factory produces instances of '%s', but should produce instances of '%s'",
feignClientName, exampleFallback.getClass(), target.type()));
}*/
return builder.target(target, fallbackFactory);
}
示例6: targetWithFallbackFactory
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
private <T> T targetWithFallbackFactory(String feignClientName, FeignContext context,
Target.HardCodedTarget<T> target,
HystrixFeign.Builder builder,
Class<?> fallbackFactoryClass) {
FallbackFactory<? extends T> fallbackFactory = (FallbackFactory<? extends T>)
getFromContext("fallbackFactory", feignClientName, context, fallbackFactoryClass, FallbackFactory.class);
/* We take a sample fallback from the fallback factory to check if it returns a fallback
that is compatible with the annotated feign interface. */
Object exampleFallback = fallbackFactory.create(new RuntimeException());
Assert.notNull(exampleFallback,
String.format(
"Incompatible fallbackFactory instance for feign client %s. Factory may not produce null!",
feignClientName));
if (!target.type().isAssignableFrom(exampleFallback.getClass())) {
throw new IllegalStateException(
String.format(
"Incompatible fallbackFactory instance for feign client %s. Factory produces instances of '%s', but should produce instances of '%s'",
feignClientName, exampleFallback.getClass(), target.type()));
}
return builder.target(target, fallbackFactory);
}
示例7: simpleFeignBuilder
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
public static HystrixFeign.Builder simpleFeignBuilder() {
JacksonDecoder decoder = new JacksonDecoder(defaultObjectMapper);
return HystrixFeign.builder()
.setterFactory(new DefaultSetterFactory())
.logger(new Slf4jLogger())
.logLevel(Logger.Level.FULL)
.retryer(new Retryer.Default())
.contract(new Contract.Default())
.client(new OkHttpClient())
.options(new Request.Options())
.encoder(new JacksonEncoder(defaultObjectMapper))
.decoder(decoder)
.errorDecoder(new AccessApiErrorDecoder(decoder));
}
示例8: holaService
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
/**
* This is were the "magic" happens: it creates a Feign, which is a proxy interface for remote calling a
* REST endpoint with Hystrix fallback support.
*/
@Bean
public HolaService holaService() {
return HystrixFeign.builder()
.logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC)
.decoder(new JacksonDecoder())
.requestInterceptor(this::applyTracingHeaders) // extra tracing headers required to be propagated
.target(HolaService.class, "http://istio-ingress/",
() -> Collections.singletonList("Hola response (fallback)"));
}
示例9: getClient
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
@Override
protected Feign getClient() {
return feign = HystrixFeign.builder()
.client(new TracingClient(new Client.Default(null, null), mockTracer))
.retryer(new Retryer.Default(100, SECONDS.toMillis(1), FeignTracingTest.NUMBER_OF_RETRIES))
.build();
}
示例10: run
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
public void run() {
GoodByeService service = HystrixFeign.builder()
// Target REST resource
.target(GoodByeService.class,
// Server
"http://localhost:8080/",
// Fallback implemenation
() -> "Nap response (fallback)");
// Service invocation
String result = service.nap();
System.out.println(String.format("#%s - %s", this.getName(), result));
}
示例11: holaService
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
/**
*
* This is were the "magic" happens: it creates a Feign, which is a proxy interface for remote calling a
* REST endpoint with Hystrix fallback support.
*/
@Bean
public HolaService holaService(Tracer tracer) {
// bind current span to Hystrix thread
TracingConcurrencyStrategy.register();
return HystrixFeign.builder()
.client(new TracingClient(new ApacheHttpClient(HttpClientBuilder.create().build()), tracer))
.logger(new Logger.ErrorLogger()).logLevel(Logger.Level.BASIC)
.decoder(new JacksonDecoder())
.target(HolaService.class, "http://hola:8080/",
() -> Collections.singletonList("Hola response (fallback)"));
}
示例12: builder
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
static Feign.Builder builder(BeanFactory beanFactory) {
return HystrixFeign.builder()
.client(new TraceFeignClient(beanFactory))
.retryer(new TraceFeignRetryer(beanFactory))
.decoder(new TraceFeignDecoder(beanFactory))
.errorDecoder(new TraceFeignErrorDecoder(beanFactory));
}
示例13: feignHystrixBuilder
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "feign.hystrix.enabled")
public Feign.Builder feignHystrixBuilder() {
return HystrixFeign.builder();
}
示例14: feignBuilder
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
@Bean
public Feign.Builder feignBuilder() {
return HystrixFeign.builder();
}
示例15: client
import feign.hystrix.HystrixFeign; //导入依赖的package包/类
protected HystrixFeign.Builder client() {
return HystrixFeign.builder().logger(new Slf4jLogger()).retryer(new Retryer.Default())
.logLevel(Logger.Level.FULL);
}