@Test public void testFallback() throws IOException { HttpResourceGroup group = Ribbon.createHttpResourceGroup("myclient", ClientOptions.create() .withConfigurationBasedServerList("localhost:12345") .withMaxAutoRetriesNextServer(1)); final String fallback = "fallback"; HttpRequestTemplate<ByteBuf> template = group.newTemplateBuilder("test", ByteBuf.class) .withUriTemplate("/") .withMethod("GET") .withFallbackProvider(new FallbackHandler<ByteBuf>() { @Override public Observable<ByteBuf> getFallback( HystrixInvokableInfo<?> hystrixInfo, Map<String, Object> requestProperties) { try { return Observable.just(Unpooled.buffer().writeBytes(fallback.getBytes("UTF-8"))); } catch (UnsupportedEncodingException e) { return Observable.error(e); } } }).build(); RibbonRequest<ByteBuf> request = template .requestBuilder().build(); final AtomicReference<HystrixInvokableInfo<?>> hystrixInfo = new AtomicReference<HystrixInvokableInfo<?>>(); final AtomicBoolean failed = new AtomicBoolean(false); Observable<String> result = request.withMetadata().toObservable().flatMap(new Func1<RibbonResponse<Observable<ByteBuf>>, Observable<String>>(){ @Override public Observable<String> call( final RibbonResponse<Observable<ByteBuf>> response) { hystrixInfo.set(response.getHystrixInfo()); failed.set(response.getHystrixInfo().isFailedExecution()); return response.content().map(new Func1<ByteBuf, String>(){ @Override public String call(ByteBuf t1) { return t1.toString(Charset.defaultCharset()); } }); } }); String s = result.toBlocking().single(); assertTrue(hystrixInfo.get().isResponseFromFallback()); assertTrue(failed.get()); assertEquals(fallback, s); }
public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); static Builder createHttpResourceGroupBuilder(String name); static HttpResourceGroup createHttpResourceGroup(String name); static HttpResourceGroup createHttpResourceGroup(String name, ClientOptions options); static T from(Class<T> contract); }
Ribbon { public static HttpResourceGroup createHttpResourceGroup(String name) { return factory.createHttpResourceGroup(name); } private  Ribbon(); static Builder createHttpResourceGroupBuilder(String name); static HttpResourceGroup createHttpResourceGroup(String name); static HttpResourceGroup createHttpResourceGroup(String name, ClientOptions options); static T from(Class<T> contract);  }