kptfh / feign-reactive Goto Github PK
View Code? Open in Web Editor NEWReactive Feign client based on Spring WebFlux
License: Apache License 2.0
Reactive Feign client based on Spring WebFlux
License: Apache License 2.0
Hi, I'd like to create a simple client like this:
package com.kgregorczyk.store_example.library.clients;
import feign.Param;
import feign.RequestLine;
import reactivefeign.ReactiveFeign;
import reactor.core.publisher.Mono;
public interface CategoryFeignClient {
@RequestLine("GET /{categoryId}/exists")
Mono<Boolean> categoryExists(@Param("categoryId") String categoryId);
static CategoryFeignClient createClient(String url) {
return ReactiveFeign.builder().target(CategoryFeignClient.class, url);
}
}
but I'm getting compilation errors saying that
incompatible types: java.lang.Class<com.kgregorczyk.store_example.library.clients.CategoryFeignClient> cannot be converted to java.lang.Class<java.lang.Object>
and i get it, it should be a class not an interface but how am I supposed to create a new instance of it ?
Hi, for some reason maven cannot download/find this repo, I added
<repositories>
<repository>
<id>bintray-kptfh-feign-reactive</id>
<name>bintray</name>
<url>https://dl.bintray.com/kptfh/feign-reactive</url>
</repository>
</repositories>
in the project level and
<dependency>
<groupId>io.github.reactivefeign</groupId>
<artifactId>feign-reactive-core</artifactId>
<version>0.6.0</version>
</dependency>
<dependency>
<groupId>io.github.reactivefeign</groupId>
<artifactId>feign-reactive-cloud</artifactId>
<version>0.6.0</version>
</dependency>
in the dependencies section but for some reason I'm getting:
Could not resolve dependencies for project com.kgregorczyk.store_example:product:jar:0.0.2: Could not find artifact io.github.reactivefeign:feign-reactive:jar:0.6.0 in bintray-kptfh-feign-reactive
Here's my full pom file https://pastebin.com/pMHibgkw
注册中心采用的是nacos,使用feign或者feign-reactive。都会导致项目启动不了,nacos未正常注册,也没有任何报错。
Hi, what about writing an adapter for the kotlin coroutine compatibility?
package com.demo.feign
import kotlinx.coroutines.flow.Flow
import org.springframework.web.bind.annotation.GetMapping
import reactivefeign.spring.config.ReactiveFeignClient
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
@ReactiveFeignClient(
name = "helloClient",
url = "http://localhost:8080"
)
interface HelloClient {
@GetMapping("/hello")
fun helloMono(): Mono<String>
@GetMapping("/hello")
suspend fun helloKotlinMono(): String
@GetMapping("/hello")
fun helloFlux(): Flux<String>
@GetMapping("/hello")
fun helloKotlinFlux(): Flow<String>
}
Hello,
I'm currently constructing multiple feign clients using the WebReactiveFeign.Builder api. However this class is not using the httpClient configured before in the webclient. ( my httpClient use sslContext that trust all certs but the feignClient is not using it)
to be clear this is my configuration :
@Configuration
public class FeignConfiguration {
// ssl context trusting all certificates
@Bean
public SslContext sslContext() throws Exception {
SslContext sslContext = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();
return sslContext;
}
@Bean
public ClientHttpConnector httpConnector(SslContext sslContext) {
HttpClient httpClient = HttpClient.create().secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));
return new ReactorClientHttpConnector(httpClient);
}
@Bean
public WebClient webClient(ClientHttpConnector httpConnector, ObjectMapper mapper) {
ExchangeStrategies strategies = ExchangeStrategies
.builder()
.codecs(configurer -> {
configurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper));
configurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper));
}).build();
return WebClient.builder().clientConnector(httpConnector).exchangeStrategies(strategies).build();
}
@Bean
public WebReactiveFeign.Builder reactiveFeignBuilder(WebClient webClient) {
return WebReactiveFeign.builder(webClient.mutate());
}
}
so when I use the bean WebReactiveFeign.Builder to create feignClients dynamically I got an ssl exception ( which means is not using my sslContext as configured in the httpClient -> webclient bean)
the ssl exception is :
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
However if I pass the httpClient bean to the WebReactiveFeign.Builder directly ( as below ) it use the insecure sslContext without any exception :
@Bean
public HttpClient httpConnector(SecurityProperties securityProps, SslContext sslContext) {
HttpClient httpClient = HttpClient.create().secure(sslContextSpec -> sslContextSpec.sslContext(sslContext));
SecurityProperties.ProxyServer proxyServer = securityProps.getProxy();
if (proxyServer != null) {
httpClient.proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP)
.host(proxyServer.getHost())
.port(proxyServer.getPort())
.username(proxyServer.getUsername())
.password(u -> proxyServer.getPassword()));
}
return httpClient;
}
@Bean
public WebClient webClient(HttpClient httpClient, ObjectMapper mapper) {
ExchangeStrategies strategies = ExchangeStrategies
.builder()
.codecs(configurer -> {
configurer.defaultCodecs().jackson2JsonEncoder(new Jackson2JsonEncoder(mapper));
configurer.defaultCodecs().jackson2JsonDecoder(new Jackson2JsonDecoder(mapper));
}).build();
return WebClient.builder().clientConnector(new ReactorClientHttpConnector(httpClient)).exchangeStrategies(strategies).build();
}
@Bean
public WebReactiveFeign.Builder reactiveFeignBuilder(WebClient webClient, HttpClient httpClient) {
WebReactiveFeign.Builder<Object> builder = WebReactiveFeign.builder(webClient.mutate());
builder.httpClient(httpClient);
return builder;
}
do you think it's WebReactiveFeign.Builder bug?
FYI I'm using :
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-spring-cloud-starter</artifactId>
<version>3.2.6</version>
<type>pom</type>
</dependency>
thank you in advance for your help ;)
Best regards,
Med
Hello, I am currently using your repo but unfortunately I can not disable Hystrix with the configuration: feign.hystrix.enabled = false.
there is always the circuit breaker that is active with the fallback.
I also can not disable the timeout.
could you help me please ?
Thanks
When the response contains multiple headers with the same key it throws a generic error, whereas their value should be collapsed together.
Hi, in the readme file you are using unknown annotations (at least, to me) like @RequestLine("GET /icecream/flavors")
which dependency contains them?
I am not able to configure the line
.withLoadBalancer(AbstractLoadBalancer.class.cast(getNamedLoadBalancer(serviceName)))
to use ribbon DynamicServerlistLoadBalancer. Any help would be appriciated.
IcecreamServiceApi client = CloudReactiveFeign.builder()
.setFallback(new TestInterface() {
@OverRide
public Mono get() {
return Mono.just("fallback");
}
})
.setLoadBalancerCommand(
LoadBalancerCommand.builder()
.withLoadBalancer(AbstractLoadBalancer.class.cast(getNamedLoadBalancer(serviceName)))
.withRetryHandler(new DefaultLoadBalancerRetryHandler(1, 1, true))
.build()
)
.target(IcecreamServiceApi.class, "http://" + serviceName);
feign.reactor.version=1.0.30
Final request path: ReactiveFeignClient.path + "/" + GetMapping.value
If GetMapping.value is default "/" is added anyway.
The behavior is different from FeignClient
Example:
@GetMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
Result get(@RequestParam(value = "param") );
@ReactiveFeignClient(
path = "/my/path",
)
Expected (non reactive feign-client behaviour):
/my/path?param=...
Real: additional '/' is added after ReactiveFeignClient.path
/my/path/?param=...
The request for the first time take very long.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.