Commit 8e1b9b20 authored by Tejas Sharma's avatar Tejas Sharma

added custom property in application.yml and removed the base url from service...

added custom property in application.yml and removed the base url from service layer and configured in webclient config
parent 93388320
package org.nisum.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
......@@ -7,8 +8,11 @@ import org.springframework.web.reactive.function.client.WebClient;
@Configuration
public class WebClientConfig {
@Value("${custom.webclient.base-url}")
private String baseUrl;
@Bean
public WebClient.Builder webClientBuilder(){
return WebClient.builder().baseUrl("");
return WebClient.builder().baseUrl(baseUrl);
}
}
......@@ -91,14 +91,14 @@ public class InventoryService {
// instead of string make it return object for both parallel and sequential
// instead of hardcoding the base url create a property in yml and pass it in web client config file
public Mono<List<Product>> getSequentialInventoryDetails(){
return webClientBuilder.baseUrl("https://dummyjson.com")
return webClientBuilder
.build()
.get()
.uri("/products/1")
.retrieve()
.bodyToMono(Product.class)
.flatMap(s ->
webClientBuilder.baseUrl("https://dummyjson.com")
webClientBuilder
.build()
.get()
.uri("/products/2")
......@@ -110,13 +110,13 @@ public class InventoryService {
//parallel request response model
public Mono<List<Product>> getParallelInventoryDetails(){
Mono<Product> product1 =webClientBuilder.baseUrl("https://dummyjson.com")
Mono<Product> product1 =webClientBuilder
.build()
.get()
.uri("/products/1")
.retrieve()
.bodyToMono(Product.class);
Mono<Product> product2 =webClientBuilder.baseUrl("https://dummyjson.com")
Mono<Product> product2 =webClientBuilder
.build()
.get()
.uri("/products/2")
......
......@@ -10,3 +10,6 @@ spring:
mvc:
locale: en #Points to the base name of the message files. In this case, we use messages.properties, messages_en.properties, etc.
locale-resolver: accept-header #We are using the AcceptHeaderLocaleResolver that will automatically resolve the locale based on the Accept-Language header in the HTTP request.
custom:
webclient:
base-url: "https://dummyjson.com"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment