当前位置: 首页>>代码示例>>Java>>正文


Java HystrixFeign类代码示例

本文整理汇总了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());

}
 
开发者ID:xstefank,项目名称:lra-service,代码行数:19,代码来源:BeanConfiguration.java

示例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)"));
}
 
开发者ID:redhat-helloworld-msa,项目名称:hola,代码行数:23,代码来源:TracingConfiguration.java

示例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)"));
}
 
开发者ID:redhat-helloworld-msa,项目名称:hello,代码行数:27,代码来源:HelloResource.java

示例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);
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:26,代码来源:AlertsPublisher.java

示例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);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:22,代码来源:EnhanceHystrixTargeter.java

示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:22,代码来源:HystrixTargeter.java

示例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));
}
 
开发者ID:amvnetworks,项目名称:amv-access-api-poc,代码行数:15,代码来源:Clients.java

示例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)"));
}
 
开发者ID:redhat-developer-demos,项目名称:istio-ola,代码行数:14,代码来源:TracingConfiguration.java

示例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();
}
 
开发者ID:OpenFeign,项目名称:feign-opentracing,代码行数:8,代码来源:HystrixFeignTracingTest.java

示例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));
}
 
开发者ID:redhat-helloworld-msa,项目名称:goodbye,代码行数:13,代码来源:HystrixClient.java

示例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)"));
}
 
开发者ID:redhat-helloworld-msa,项目名称:ola,代码行数:18,代码来源:TracingConfiguration.java

示例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));
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:8,代码来源:SleuthFeignBuilder.java

示例13: feignHystrixBuilder

import feign.hystrix.HystrixFeign; //导入依赖的package包/类
@Bean
@Scope("prototype")
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "feign.hystrix.enabled")
public Feign.Builder feignHystrixBuilder() {
	return HystrixFeign.builder();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:8,代码来源:FeignClientsConfiguration.java

示例14: feignBuilder

import feign.hystrix.HystrixFeign; //导入依赖的package包/类
@Bean
public Feign.Builder feignBuilder() {
    return HystrixFeign.builder();
}
 
开发者ID:rsdomingues,项目名称:netflixmicroservices-tdc2017,代码行数:5,代码来源:FeignConfig.java

示例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);
}
 
开发者ID:januslabs,项目名称:consul-ribbon-starter,代码行数:5,代码来源:RibbonFeignClientConfig.java


注:本文中的feign.hystrix.HystrixFeign类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。