testing inter service communication
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
38
src/main/java/dev/mars3142/fhq/config/RestClientConfig.java
Normal file
38
src/main/java/dev/mars3142/fhq/config/RestClientConfig.java
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user