com.netflix.ribbon.RibbonResourceFactory Java Examples
The following examples show how to use
com.netflix.ribbon.RibbonResourceFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RxMovieProxyExampleTest.java From ribbon with Apache License 2.0 | 6 votes |
@Test public void shouldBindCustomClientConfigFactory() { ConfigurationManager.getConfigInstance().setProperty(MovieService.class.getSimpleName() + ".MyConfig.listOfServers", "localhost:" + port); Injector injector = Guice.createInjector( new AbstractModule() { @Override protected void configure() { bind(RibbonResourceFactory.class).to(DefaultResourceFactory.class).in(Scopes.SINGLETON); bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON); bind(AnnotationProcessorsProvider.class).to(DefaultAnnotationProcessorsProvider.class).in(Scopes.SINGLETON); bind(ClientConfigFactory.class).to(MyClientConfigFactory.class).in(Scopes.SINGLETON); } }, new AbstractModule() { @Override protected void configure() { bind(MovieService.class).toProvider(new RibbonResourceProvider<MovieService>(MovieService.class)).asEagerSingleton(); } } ); RxMovieProxyExample example = injector.getInstance(RxMovieProxyExample.class); assertTrue(example.runExample()); }
Example #2
Source File: ClientPropertiesTest.java From ribbon with Apache License 2.0 | 6 votes |
@Test public void testAnnotation() { MyTransportFactory transportFactory = new MyTransportFactory(ClientConfigFactory.DEFAULT); RibbonResourceFactory resourceFactory = new DefaultResourceFactory(ClientConfigFactory.DEFAULT, transportFactory); RibbonDynamicProxy.newInstance(SampleMovieService.class, resourceFactory, ClientConfigFactory.DEFAULT, transportFactory); IClientConfig clientConfig = transportFactory.getClientConfig(); assertEquals(1000, clientConfig.get(Keys.ConnectTimeout).longValue()); assertEquals(2000, clientConfig.get(Keys.ReadTimeout).longValue()); Configuration config = ConfigurationManager.getConfigInstance(); assertEquals("2000", config.getProperty("SampleMovieService.ribbon.ReadTimeout")); assertEquals("1000", config.getProperty("SampleMovieService.ribbon.ConnectTimeout")); config.setProperty("SampleMovieService.ribbon.ReadTimeout", "5000"); assertEquals(5000, clientConfig.get(Keys.ReadTimeout).longValue()); }
Example #3
Source File: ClientPropertiesProcessor.java From ribbon with Apache License 2.0 | 6 votes |
@Override public void process(String groupName, GroupBuilder groupBuilder, RibbonResourceFactory resourceFactory, Class<?> interfaceClass) { ClientProperties properties = interfaceClass.getAnnotation(ClientProperties.class); if (properties != null) { IClientConfig config = resourceFactory.getClientConfigFactory().newConfig(); for (Property prop : properties.properties()) { String name = prop.name(); config.set(CommonClientConfigKey.valueOf(name), prop.value()); } ClientOptions options = ClientOptions.from(config); groupBuilder.withClientOptions(options); if (properties.exportToArchaius()) { exportPropertiesToArchaius(groupName, config, interfaceClass.getName()); } } }
Example #4
Source File: RibbonModule.java From ribbon with Apache License 2.0 | 5 votes |
@Override protected void configure() { bind(ClientConfigFactory.class).toInstance(ClientConfigFactory.DEFAULT); bind(RibbonTransportFactory.class).to(DefaultRibbonTransportFactory.class).in(Scopes.SINGLETON); bind(AnnotationProcessorsProvider.class).to(DefaultAnnotationProcessorsProvider.class).in(Scopes.SINGLETON); bind(RibbonResourceFactory.class).to(DefaultResourceFactory.class).in(Scopes.SINGLETON); }
Example #5
Source File: RibbonDynamicProxyTest.java From ribbon with Apache License 2.0 | 5 votes |
@Test public void testSetupWithResourceGroupNameInAnnotation() throws Exception { mockStatic(ProxyHttpResourceGroupFactory.class); expectNew(ProxyHttpResourceGroupFactory.class, new Class[]{ClassTemplate.class, RibbonResourceFactory.class, AnnotationProcessorsProvider.class }, anyObject(), anyObject(), anyObject()).andReturn(httpResourceGroupFactoryMock); replayAll(); RibbonDynamicProxy.newInstance(SampleMovieServiceWithResourceGroupNameAnnotation.class); }
Example #6
Source File: ClientPropertiesTest.java From ribbon with Apache License 2.0 | 5 votes |
@Test public void testNoExportToArchaius() { MyTransportFactory transportFactory = new MyTransportFactory(ClientConfigFactory.DEFAULT); RibbonResourceFactory resourceFactory = new DefaultResourceFactory(ClientConfigFactory.DEFAULT, transportFactory); RibbonDynamicProxy.newInstance(MovieService.class, resourceFactory, ClientConfigFactory.DEFAULT, transportFactory); IClientConfig clientConfig = transportFactory.getClientConfig(); assertEquals(1000, clientConfig.get(Keys.ConnectTimeout).longValue()); assertEquals(3000, clientConfig.get(Keys.ReadTimeout).longValue()); assertEquals(0, clientConfig.get(Keys.MaxAutoRetriesNextServer).longValue()); Configuration config = ConfigurationManager.getConfigInstance(); assertNull(config.getProperty("MovieService.ribbon.ReadTimeout")); config.setProperty("MovieService.ribbon.ReadTimeout", "5000"); assertEquals(5000, clientConfig.get(Keys.ReadTimeout).longValue()); }
Example #7
Source File: RibbonDynamicProxy.java From ribbon with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> clientInterface, RibbonResourceFactory resourceGroupFactory, ClientConfigFactory configFactory, RibbonTransportFactory transportFactory, AnnotationProcessorsProvider processors) { if (!clientInterface.isInterface()) { throw new IllegalArgumentException(clientInterface.getName() + " is a class not interface"); } return (T) Proxy.newProxyInstance( Thread.currentThread().getContextClassLoader(), new Class[]{clientInterface, ProxyLifeCycle.class}, new RibbonDynamicProxy<T>(clientInterface, resourceGroupFactory, configFactory, transportFactory, processors) ); }
Example #8
Source File: RibbonDynamicProxy.java From ribbon with Apache License 2.0 | 5 votes |
public RibbonDynamicProxy(Class<T> clientInterface, RibbonResourceFactory resourceGroupFactory, ClientConfigFactory configFactory, RibbonTransportFactory transportFactory, AnnotationProcessorsProvider processors) { registerAnnotationProcessors(processors); ClassTemplate<T> classTemplate = ClassTemplate.from(clientInterface); HttpResourceGroup httpResourceGroup = new ProxyHttpResourceGroupFactory<T>(classTemplate, resourceGroupFactory, processors).createResourceGroup(); templateExecutorMap = MethodTemplateExecutor.from(httpResourceGroup, clientInterface, processors); lifeCycle = new ProxyLifecycleImpl(httpResourceGroup); }
Example #9
Source File: RibbonModuleTest.java From ribbon with Apache License 2.0 | 5 votes |
@Inject public MyService(RibbonResourceFactory factory) { httpResourceGroup = factory.createHttpResourceGroup("movieServiceClient", ClientOptions.create() .withMaxAutoRetriesNextServer(3) .withConfigurationBasedServerList("localhost:" + PORT)); registerMovieTemplate = httpResourceGroup.newTemplateBuilder("registerMovie", ByteBuf.class) .withMethod("POST") .withUriTemplate("/movies") .withHeader("X-Platform-Version", "xyz") .withHeader("X-Auth-Token", "abc") .withResponseValidator(new RecommendationServiceResponseValidator()).build(); updateRecommendationTemplate = httpResourceGroup.newTemplateBuilder("updateRecommendation", ByteBuf.class) .withMethod("POST") .withUriTemplate("/users/{userId}/recommendations") .withHeader("X-Platform-Version", "xyz") .withHeader("X-Auth-Token", "abc") .withResponseValidator(new RecommendationServiceResponseValidator()).build(); recommendationsByUserIdTemplate = httpResourceGroup.newTemplateBuilder("recommendationsByUserId", ByteBuf.class) .withMethod("GET") .withUriTemplate("/users/{userId}/recommendations") .withHeader("X-Platform-Version", "xyz") .withHeader("X-Auth-Token", "abc") .withFallbackProvider(new RecommendationServiceFallbackHandler()) .withResponseValidator(new RecommendationServiceResponseValidator()).build(); recommendationsByTemplate = httpResourceGroup.newTemplateBuilder("recommendationsBy", ByteBuf.class) .withMethod("GET") .withUriTemplate("/recommendations?category={category}&ageGroup={ageGroup}") .withHeader("X-Platform-Version", "xyz") .withHeader("X-Auth-Token", "abc") .withFallbackProvider(new RecommendationServiceFallbackHandler()) .withResponseValidator(new RecommendationServiceResponseValidator()).build(); }
Example #10
Source File: CacheProviderAnnotationProcessor.java From ribbon with Apache License 2.0 | 4 votes |
@Override public void process(String groupName, GroupBuilder groupBuilder, RibbonResourceFactory resourceFactory, Class<?> interfaceClass) { }
Example #11
Source File: HttpAnnotationProcessor.java From ribbon with Apache License 2.0 | 4 votes |
@Override public void process(String groupName, HttpResourceGroup.Builder groupBuilder, RibbonResourceFactory resourceFactory, Class<?> interfaceClass) { }
Example #12
Source File: HystrixAnnotationProcessor.java From ribbon with Apache License 2.0 | 4 votes |
@Override public void process(String groupName, HttpResourceGroup.Builder groupBuilder, RibbonResourceFactory resourceFactory, Class<?> interfaceClass) { }
Example #13
Source File: RibbonDynamicProxy.java From ribbon with Apache License 2.0 | 4 votes |
public static <T> T newInstance(Class<T> clientInterface, RibbonResourceFactory resourceGroupFactory, ClientConfigFactory configFactory, RibbonTransportFactory transportFactory) { return newInstance(clientInterface, resourceGroupFactory, configFactory, transportFactory, AnnotationProcessorsProvider.DEFAULT); }
Example #14
Source File: ProxyHttpResourceGroupFactory.java From ribbon with Apache License 2.0 | 4 votes |
ProxyHttpResourceGroupFactory(ClassTemplate<T> classTemplate, RibbonResourceFactory httpResourceGroupFactory, AnnotationProcessorsProvider processors) { this.classTemplate = classTemplate; this.httpResourceGroupFactory = httpResourceGroupFactory; this.processors = processors; }
Example #15
Source File: RibbonResourceProvider.java From ribbon with Apache License 2.0 | 4 votes |
@Inject @Toolable protected void initialize(RibbonResourceFactory factory) { this.factory = factory; }
Example #16
Source File: EVCacheAnnotationProcessor.java From ribbon with Apache License 2.0 | 4 votes |
@Override public void process(String groupName, GroupBuilder groupBuilder, RibbonResourceFactory factory, Class<?> interfaceClass) { }
Example #17
Source File: AnnotationProcessor.java From ribbon with Apache License 2.0 | votes |
void process(String groupName, T groupBuilder, RibbonResourceFactory resourceFactory, Class<?> interfaceClass);