Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve web client reactor #153

Merged
merged 2 commits into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
4 changes: 4 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

Expand Down Expand Up @@ -81,6 +84,7 @@ set CMD_LINE_ARGS=%*

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void buildModule(ModuleBuilder builder) throws IOException, CleanExceptio
builder.setupFromTemplate("driven-adapter/consumer-rest/reactive-rest-consumer");
builder.appendDependencyToModule(
"app-service", "compile 'org.springframework.boot:spring-boot-starter-webflux'");
builder.appendToProperties("adapter.restconsumer").put("timeout", 5000);
} else {
logger.lifecycle("Generating rest-consumer for imperative project");
builder.setupFromTemplate("driven-adapter/consumer-rest/rest-consumer");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
package {{package}}.config;

package co.com.bancolombia.config;

import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.handler.timeout.WriteTimeoutHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.reactive.ClientHttpConnector;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;

import static io.netty.channel.ChannelOption.CONNECT_TIMEOUT_MILLIS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

@Configuration
public class RestConsumerConfig {

@Value("${adapter.restconsumer.url}")
private String url;
@Value("${adapter.restconsumer.timeout}")
private int timeout;

@Bean
public WebClient getWebClient() {
return WebClient.builder()
.baseUrl(url)
.defaultHeader(HttpHeaders.CONTENT_TYPE, "application/json")
.clientConnector(getClientHttpConnector())
.build();
}

private ClientHttpConnector getClientHttpConnector() {
/*
IF YO REQUIRE APPEND SSL CERTIFICATE SELF SIGNED
SslContext sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE)
.build();*/
return new ReactorClientHttpConnector(HttpClient.create()
//.secure(sslContextSpec -> sslContextSpec.sslContext(sslContext))
.compress(true)
.keepAlive(true)
.option(CONNECT_TIMEOUT_MILLIS, timeout)
.doOnConnected(connection -> {
connection.addHandlerLast(new ReadTimeoutHandler(timeout, MILLISECONDS));
connection.addHandlerLast(new WriteTimeoutHandler(timeout, MILLISECONDS));
}));
}

}