testing inter service communication

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2024-10-16 21:48:24 +02:00
parent d6598742e9
commit 837d10a1b9
28 changed files with 89 additions and 229 deletions

View File

@@ -0,0 +1,38 @@
package dev.mars3142.fhq.config;
import dev.mars3142.fhq.client.TimeZoneClient;
import org.springframework.boot.web.client.ClientHttpRequestFactories;
import org.springframework.boot.web.client.ClientHttpRequestFactorySettings;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.support.RestClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
@Configuration
public class RestClientConfig {
@LoadBalanced
@Bean
RestClient.Builder restClientBuilder() {
return RestClient.builder();
}
@Bean
public TimeZoneClient timeZoneClient(RestClient.Builder restClientBuilder) {
RestClient restClient = restClientBuilder
.baseUrl("http://timezone-service")
.requestFactory(getClientRequestFactory())
.build();
var restClientAdapter = RestClientAdapter.create(restClient);
var httpServiceProxyFactory = HttpServiceProxyFactory.builderFor(restClientAdapter).build();
return httpServiceProxyFactory.createClient(TimeZoneClient.class);
}
private ClientHttpRequestFactory getClientRequestFactory() {
ClientHttpRequestFactorySettings clientHttpRequestFactorySettings = ClientHttpRequestFactorySettings.DEFAULTS;
return ClientHttpRequestFactories.get(clientHttpRequestFactorySettings);
}
}