Skip to content

Commit

Permalink
Renamed feign-reactor-webclient to feign-reactor-webclient-netty
Browse files Browse the repository at this point in the history
Added HTTP2 support for Netty client
  • Loading branch information
skarpenko committed Nov 10, 2023
1 parent 114a56c commit 21f993e
Show file tree
Hide file tree
Showing 61 changed files with 416 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: 2 # use CircleCI 2.0
jobs: # a collection of steps
build:
environment:
# Configure the JVMto avoid OOM errors
# Configure the JVM to avoid OOM errors
_JAVA_OPTIONS: "-Xmx3g"
docker: # run the steps with Docker
- image: circleci/openjdk:17.0.1-jdk-buster
Expand Down
2 changes: 1 addition & 1 deletion feign-reactor-benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-webclient</artifactId>
<artifactId>feign-reactor-webclient-netty</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import reactivefeign.java11.Java11ReactiveOptions;
import reactivefeign.jetty.JettyReactiveFeign;
import reactivefeign.jetty.JettyReactiveOptions;
import reactivefeign.webclient.WebReactiveFeign;
import reactivefeign.webclient.netty.NettyWebReactiveFeign;
import reactor.core.publisher.Mono;

import java.io.IOException;
Expand Down Expand Up @@ -86,7 +86,7 @@ protected void setup() throws Exception {

webClient = WebClient.create();

webClientFeign = WebReactiveFeign.<FeignReactorTestInterface>builder()
webClientFeign = NettyWebReactiveFeign.<FeignReactorTestInterface>builder()
.target(FeignReactorTestInterface.class, SERVER_URL);

jettyHttpClient = new HttpClient();
Expand Down
2 changes: 1 addition & 1 deletion feign-reactor-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</dependency>
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-webclient</artifactId>
<artifactId>feign-reactor-webclient-netty</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion feign-reactor-cloud/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<!-- Tests -->
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-webclient</artifactId>
<artifactId>feign-reactor-webclient-netty</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JConfigBuilder;
import org.springframework.cloud.client.circuitbreaker.ConfigBuilder;
import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory;
import reactivefeign.webclient.WebReactiveFeign;
import reactivefeign.webclient.netty.NettyWebReactiveFeign;

import java.time.Duration;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -16,7 +16,7 @@ public class BuilderUtils {
private static final AtomicInteger uniqueCircuitBreakerCounter = new AtomicInteger();

static <T> CloudReactiveFeign.Builder<T> cloudBuilder(){
return CloudReactiveFeign.<T>builder(WebReactiveFeign.builder());
return CloudReactiveFeign.<T>builder(NettyWebReactiveFeign.builder());
}

static <T> CloudReactiveFeign.Builder<T> cloudBuilder(ReactiveCircuitBreakerFactory circuitBreakerFactory){
Expand All @@ -38,7 +38,7 @@ static <T> CloudReactiveFeign.Builder<T> cloudBuilderWithUniqueCircuitBreaker(
Consumer<ConfigBuilder> customizer,
AtomicReference<String> lastCircuitBreakerId) {
int uniqueId = uniqueCircuitBreakerCounter.incrementAndGet();
return CloudReactiveFeign.<T>builder(WebReactiveFeign.builder())
return CloudReactiveFeign.<T>builder(NettyWebReactiveFeign.builder())
.enableCircuitBreaker(circuitBreakerId -> {
String uniqueCircuitBreakerId = circuitBreakerId + "."+uniqueId;
if(lastCircuitBreakerId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@
import org.springframework.cloud.client.loadbalancer.reactive.ReactiveLoadBalancer;
import reactivefeign.ReactiveFeignBuilder;
import reactivefeign.testcase.IcecreamServiceApi;
import reactivefeign.webclient.WebReactiveOptions;
import reactivefeign.webclient.netty.NettyReactiveOptions;

/**
* @author Sergii Karpenko
*/
public class MetricsTest extends reactivefeign.MetricsTest {

private static String serviceName = "MetricsTest-loadBalancingDefaultPolicyRoundRobin";
private static final String serviceName = "MetricsTest-loadBalancingDefaultPolicyRoundRobin";

private static ReactiveLoadBalancer.Factory<ServiceInstance> loadBalancerFactory;
private static ReactiveLoadBalancer.Factory<ServiceInstance> loadBalancerFactory;

@BeforeClass
public static void setupServersList() {
loadBalancerFactory = LoadBalancingReactiveHttpClientTest.loadBalancerFactory(serviceName, wireMockRule.port());
}
@BeforeClass
public static void setupServersList() {
loadBalancerFactory = LoadBalancingReactiveHttpClientTest.loadBalancerFactory(serviceName, wireMockRule.port());
}

@Override
protected String getHost() {
Expand All @@ -55,7 +55,7 @@ protected Target<IcecreamServiceApi> target(){
protected ReactiveFeignBuilder<IcecreamServiceApi> builder(long readTimeoutInMillis) {
return BuilderUtils.<IcecreamServiceApi>cloudBuilder()
.enableLoadBalancer(loadBalancerFactory)
.options(new WebReactiveOptions.Builder().setReadTimeoutMillis(readTimeoutInMillis).build()
.options(new NettyReactiveOptions.Builder().setReadTimeoutMillis(readTimeoutInMillis).build()
);
}

Expand Down
36 changes: 21 additions & 15 deletions feign-reactor-core/src/test/java/reactivefeign/ReactivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;
import reactivefeign.testcase.IcecreamServiceApi;
import reactivefeign.testcase.domain.OrderGenerator;
import reactor.core.publisher.Mono;
import reactor.netty.DisposableServer;
import reactor.netty.http.HttpProtocol;
import reactor.netty.http.server.HttpServer;

import java.time.Duration;
Expand All @@ -29,7 +30,6 @@

import static org.awaitility.Awaitility.waitAtMost;
import static org.hamcrest.CoreMatchers.is;
import static reactor.netty.http.HttpProtocol.H2C;
import static reactor.netty.http.HttpProtocol.HTTP11;

/**
Expand All @@ -45,19 +45,25 @@ abstract public class ReactivityTest extends BaseReactorTest {

private static DisposableServer server;

@BeforeClass
public static void startServer() throws JsonProcessingException {
byte[] data = TestUtils.MAPPER.writeValueAsString(new OrderGenerator().generate(1)).getBytes();

server = HttpServer.create()
.protocol(HTTP11, H2C)
.route(r -> r.get("/icecream/orders/1",
(req, res) -> {
res.header("Content-Type", "application/json");
return Mono.delay(Duration.ofMillis(DELAY_IN_MILLIS))
.thenEmpty(res.sendByteArray(Mono.just(data)));
}))
.bindNow();
@Before
public void startServer() throws JsonProcessingException {
if(server == null) {
byte[] data = TestUtils.MAPPER.writeValueAsString(new OrderGenerator().generate(1)).getBytes();

server = HttpServer.create()
.protocol(serverProtocols())
.route(r -> r.get("/icecream/orders/1",
(req, res) -> {
res.header("Content-Type", "application/json");
return Mono.delay(Duration.ofMillis(DELAY_IN_MILLIS))
.thenEmpty(res.sendByteArray(Mono.just(data)));
}))
.bindNow();
}
}

protected HttpProtocol[] serverProtocols(){
return new HttpProtocol[]{HTTP11};
}

@AfterClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@

import reactivefeign.ReactiveFeign;
import reactivefeign.testcase.IcecreamServiceApi;
import reactor.netty.http.HttpProtocol;

import static reactivefeign.java11.h2c.TestUtils.builderHttp2;
import static reactor.netty.http.HttpProtocol.H2C;
import static reactor.netty.http.HttpProtocol.HTTP11;

public class ReactivityTest extends reactivefeign.ReactivityTest {

@Override
protected HttpProtocol[] serverProtocols(){
return new HttpProtocol[]{H2C, HTTP11};
}

@Override
protected ReactiveFeign.Builder<IcecreamServiceApi> builder() {
return builderHttp2();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@
import reactivefeign.jetty.JettyReactiveFeign;
import reactivefeign.jetty.JettyReactiveOptions;
import reactivefeign.testcase.IcecreamServiceApi;
import reactor.netty.http.HttpProtocol;

import static reactor.netty.http.HttpProtocol.H2C;

public class ReactivityTest extends reactivefeign.ReactivityTest {

@Override
protected HttpProtocol[] serverProtocols(){
return new HttpProtocol[]{H2C};
}

@Override
protected ReactiveFeign.Builder<IcecreamServiceApi> builder() {
return JettyReactiveFeign.<IcecreamServiceApi>builder().options(
Expand Down
2 changes: 1 addition & 1 deletion feign-reactor-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
</dependency>
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-webclient</artifactId>
<artifactId>feign-reactor-webclient-netty</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion feign-reactor-rx2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-webclient</artifactId>
<artifactId>feign-reactor-webclient-netty</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import reactivefeign.rx2.client.statushandler.Rx2StatusHandler;
import reactivefeign.rx2.methodhandler.Rx2MethodHandlerFactory;
import reactivefeign.webclient.WebClientFeignCustomizer;
import reactivefeign.webclient.WebReactiveFeign;
import reactivefeign.webclient.netty.NettyWebReactiveFeign;
import reactivefeign.webclient.client.WebReactiveHttpClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -52,7 +52,7 @@ public static <T> Builder<T> builder(WebClient.Builder webClientBuilder, WebClie
return new Builder<>(webClientBuilder, webClientCustomizer);
}

public static class Builder<T> extends WebReactiveFeign.Builder<T> {
public static class Builder<T> extends NettyWebReactiveFeign.Builder<T> {

private BackpressureStrategy backpressureStrategy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import reactivefeign.rx2.testcase.IcecreamServiceApi;
import reactivefeign.rx2.testcase.domain.IceCreamOrder;
import reactivefeign.rx2.testcase.domain.OrderGenerator;
import reactivefeign.webclient.WebReactiveOptions;
import reactivefeign.webclient.netty.NettyReactiveOptions;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
Expand Down Expand Up @@ -95,7 +95,7 @@ public void shouldNotWrapException() {
public void shouldOverrideEquals() {

IcecreamServiceApi client = builder(
new WebReactiveOptions.Builder()
new NettyReactiveOptions.Builder()
.setReadTimeoutMillis(100)
.setConnectTimeoutMillis(300)
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import reactivefeign.ReactiveOptions;
import reactivefeign.client.ReadTimeoutException;
import reactivefeign.rx2.testcase.IcecreamServiceApi;
import reactivefeign.webclient.WebReactiveOptions;
import reactivefeign.webclient.netty.NettyReactiveOptions;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
Expand Down Expand Up @@ -48,7 +48,7 @@ public void shouldFailOnReadTimeout() throws InterruptedException {
.willReturn(aResponse().withFixedDelay(200)));

IcecreamServiceApi client = builder(
new WebReactiveOptions.Builder()
new NettyReactiveOptions.Builder()
.setReadTimeoutMillis(100)
.setConnectTimeoutMillis(300)
.build())
Expand Down
2 changes: 1 addition & 1 deletion feign-reactor-spring-cloud-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</dependency>
<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-webclient</artifactId>
<artifactId>feign-reactor-webclient-netty</artifactId>
</dependency>
</dependencies>
</project>
20 changes: 19 additions & 1 deletion feign-reactor-spring-configuration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-webclient</artifactId>
<artifactId>feign-reactor-webclient-netty</artifactId>
<optional>true</optional>
</dependency>

Expand Down Expand Up @@ -68,6 +68,24 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import reactivefeign.java11.Java11ReactiveOptions;
import reactivefeign.jetty.JettyReactiveFeign;
import reactivefeign.jetty.JettyReactiveOptions;
import reactivefeign.webclient.WebReactiveFeign;
import reactivefeign.webclient.WebReactiveOptions;
import reactivefeign.webclient.netty.NettyWebReactiveFeign;
import reactivefeign.webclient.netty.NettyReactiveOptions;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -40,13 +40,13 @@ public ReactiveFeignNamedContextFactory reactiveFeignContext() {
}

@Configuration
@ConditionalOnClass(WebReactiveFeign.class)
@ConditionalOnClass(NettyWebReactiveFeign.class)
public class WebClientReactiveFeignClientPropertiesAutoConfiguration {

@Bean
@ConditionalOnMissingBean
@ConfigurationProperties("reactive.feign.client")
public ReactiveFeignClientsProperties<WebReactiveOptions.Builder> webClientReactiveFeignClientProperties() {
public ReactiveFeignClientsProperties<NettyReactiveOptions.Builder> webClientReactiveFeignClientProperties() {
return new ReactiveFeignClientsProperties<>();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import reactivefeign.jetty.JettyHttpClientFactory;
import reactivefeign.jetty.JettyReactiveFeign;
import reactivefeign.webclient.WebClientFeignCustomizer;
import reactivefeign.webclient.WebReactiveFeign;
import reactivefeign.webclient.netty.NettyWebReactiveFeign;

import java.time.Clock;
import java.util.ArrayList;
Expand Down Expand Up @@ -124,7 +124,7 @@ public ReactiveFeignBuilder reactiveFeignBuilder(
}

@Configuration
@ConditionalOnClass({WebReactiveFeign.class, WebClient.class})
@ConditionalOnClass({NettyWebReactiveFeign.class, WebClient.class})
@ConditionalOnProperty(name = {"reactive.feign.jetty", "reactive.feign.java11"}, havingValue = "false", matchIfMissing = true)
protected static class ReactiveFeignWebConfiguration {

Expand All @@ -134,8 +134,8 @@ public ReactiveFeignBuilder reactiveFeignBuilder(
WebClient.Builder builder,
@Autowired(required = false) WebClientFeignCustomizer webClientCustomizer) {
return webClientCustomizer != null
? WebReactiveFeign.builder(builder, webClientCustomizer)
: WebReactiveFeign.builder(builder);
? NettyWebReactiveFeign.builder(builder, webClientCustomizer)
: NettyWebReactiveFeign.builder(builder);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

<dependency>
<groupId>com.playtika.reactivefeign</groupId>
<artifactId>feign-reactor-webclient</artifactId>
<artifactId>feign-reactor-webclient-netty</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Loading

0 comments on commit 21f993e

Please sign in to comment.