From 12d39e68f7d304c60c764ef508a00c2ec82f95c7 Mon Sep 17 00:00:00 2001 From: "Kristen.Herum" Date: Mon, 14 Oct 2024 15:54:52 +0200 Subject: [PATCH] Remove JacksonExchangeStrategyUtil and update WebClient configs Deleted the unused JacksonExchangeStrategyUtil class and introduced new WebClient configurations in AaregConsumer and PdlConsumer for better connection handling and performance efficiency. This change aims to improve connection stability and responsiveness in reactive web client interactions. --- .../consumers/AaregConsumer.java | 22 ++++++++++++++++ .../JacksonExchangeStrategyUtil.java | 25 ------------------- .../consumers/PdlConsumer.java | 4 +-- 3 files changed, 23 insertions(+), 28 deletions(-) delete mode 100644 apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/JacksonExchangeStrategyUtil.java diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/AaregConsumer.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/AaregConsumer.java index 2a0301db1d6..6ebf3dd5160 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/AaregConsumer.java +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/AaregConsumer.java @@ -1,5 +1,7 @@ package no.nav.testnav.levendearbeidsforholdansettelse.consumers; +import io.netty.channel.ChannelOption; +import io.netty.channel.epoll.EpollChannelOption; import lombok.extern.slf4j.Slf4j; import no.nav.testnav.levendearbeidsforholdansettelse.config.Consumers; import no.nav.testnav.levendearbeidsforholdansettelse.consumers.command.aareg.HentArbeidsforholdCommand; @@ -9,9 +11,14 @@ import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux; +import reactor.netty.http.client.HttpClient; +import reactor.netty.resources.ConnectionProvider; + +import java.time.Duration; @Slf4j @Component @@ -31,6 +38,21 @@ public AaregConsumer( this.webClient = webClientBuilder .baseUrl(serverProperties.getUrl()) + .clientConnector( + new ReactorClientHttpConnector( + HttpClient + .create(ConnectionProvider.builder("AaregConsumer") + .maxConnections(1) + .pendingAcquireMaxCount(10000) + .pendingAcquireTimeout(Duration.ofSeconds(300)) + .build()) + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000) + .option(ChannelOption.SO_KEEPALIVE, true) + .option(EpollChannelOption.TCP_KEEPIDLE, 300) + .option(EpollChannelOption.TCP_KEEPINTVL, 60) + .option(EpollChannelOption.TCP_KEEPCNT, 8) + .responseTimeout(Duration.ofSeconds(10)) + )) .build(); } diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/JacksonExchangeStrategyUtil.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/JacksonExchangeStrategyUtil.java deleted file mode 100644 index 52599728527..00000000000 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/JacksonExchangeStrategyUtil.java +++ /dev/null @@ -1,25 +0,0 @@ -package no.nav.testnav.levendearbeidsforholdansettelse.consumers; - -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.experimental.UtilityClass; -import org.springframework.http.MediaType; -import org.springframework.http.codec.json.Jackson2JsonDecoder; -import org.springframework.http.codec.json.Jackson2JsonEncoder; -import org.springframework.web.reactive.function.client.ExchangeStrategies; - -@UtilityClass -public final class JacksonExchangeStrategyUtil { - - public static ExchangeStrategies getJacksonStrategy(ObjectMapper objectMapper) { - return ExchangeStrategies.builder() - .codecs(config -> { - config.defaultCodecs() - .maxInMemorySize(32 * 1024 * 1024); - config.defaultCodecs() - .jackson2JsonEncoder(new Jackson2JsonEncoder(objectMapper, MediaType.APPLICATION_JSON)); - config.defaultCodecs() - .jackson2JsonDecoder(new Jackson2JsonDecoder(objectMapper, MediaType.APPLICATION_JSON)); - }).build(); - } - -} \ No newline at end of file diff --git a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/PdlConsumer.java b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/PdlConsumer.java index 78a55461bd8..32935d75386 100644 --- a/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/PdlConsumer.java +++ b/apps/levende-arbeidsforhold-ansettelse/src/main/java/no/nav/testnav/levendearbeidsforholdansettelse/consumers/PdlConsumer.java @@ -1,7 +1,5 @@ package no.nav.testnav.levendearbeidsforholdansettelse.consumers; -import io.netty.channel.ChannelOption; -import io.netty.channel.epoll.EpollChannelOption; import lombok.extern.slf4j.Slf4j; import lombok.val; import no.nav.testnav.levendearbeidsforholdansettelse.config.Consumers; @@ -49,7 +47,7 @@ public PdlConsumer( new ReactorClientHttpConnector( HttpClient .create(ConnectionProvider.builder("PDL connections") - .maxConnections(10) + .maxConnections(1) .pendingAcquireMaxCount(10000) .pendingAcquireTimeout(Duration.ofSeconds(30)) .build())))