mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-31 16:17:10 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
+2
-4
@@ -34,11 +34,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
public class ApiGateway {
|
||||
|
||||
@Resource
|
||||
private ImageClient imageClient;
|
||||
@Resource private ImageClient imageClient;
|
||||
|
||||
@Resource
|
||||
private PriceClient priceClient;
|
||||
@Resource private PriceClient priceClient;
|
||||
|
||||
/**
|
||||
* Retrieves product information that desktop clients need.
|
||||
|
||||
+4
-4
@@ -36,14 +36,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
* sometime in the future) or if the location (host and port) of a microservice changes, then every
|
||||
* client that makes use of those microservices must be updated.
|
||||
*
|
||||
* <p>The intent of the API Gateway pattern is to alleviate some of these issues. In the API
|
||||
* Gateway pattern, an additional entity (the API Gateway) is placed between the client and the
|
||||
* <p>The intent of the API Gateway pattern is to alleviate some of these issues. In the API Gateway
|
||||
* pattern, an additional entity (the API Gateway) is placed between the client and the
|
||||
* microservices. The job of the API Gateway is to aggregate the calls to the microservices. Rather
|
||||
* than the client calling each microservice individually, the client calls the API Gateway a single
|
||||
* time. The API Gateway then calls each of the microservices that the client needs.
|
||||
*
|
||||
* <p>This implementation shows what the API Gateway pattern could look like for an e-commerce
|
||||
* site. The {@link ApiGateway} makes calls to the Image and Price microservices using the {@link
|
||||
* <p>This implementation shows what the API Gateway pattern could look like for an e-commerce site.
|
||||
* The {@link ApiGateway} makes calls to the Image and Price microservices using the {@link
|
||||
* ImageClientImpl} and {@link PriceClientImpl} respectively. Customers viewing the site on a
|
||||
* desktop device can see both price information and an image of a product, so the {@link
|
||||
* ApiGateway} calls both of the microservices and aggregates the data in the {@link DesktopProduct}
|
||||
|
||||
+3
-10
@@ -27,21 +27,14 @@ package com.iluwatar.api.gateway;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Encapsulates all of the information that a desktop client needs to display a product.
|
||||
*/
|
||||
/** Encapsulates all of the information that a desktop client needs to display a product. */
|
||||
@Getter
|
||||
@Setter
|
||||
public class DesktopProduct {
|
||||
|
||||
/**
|
||||
* The price of the product.
|
||||
*/
|
||||
/** The price of the product. */
|
||||
private String price;
|
||||
|
||||
/**
|
||||
* The path to the image of the product.
|
||||
*/
|
||||
/** The path to the image of the product. */
|
||||
private String imagePath;
|
||||
|
||||
}
|
||||
|
||||
+1
-3
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.api.gateway;
|
||||
|
||||
/**
|
||||
* An interface used to communicate with the Image microservice.
|
||||
*/
|
||||
/** An interface used to communicate with the Image microservice. */
|
||||
public interface ImageClient {
|
||||
String getImagePath();
|
||||
}
|
||||
|
||||
+3
-7
@@ -33,9 +33,7 @@ import java.net.http.HttpResponse.BodyHandlers;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* An adapter to communicate with the Image microservice.
|
||||
*/
|
||||
/** An adapter to communicate with the Image microservice. */
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ImageClientImpl implements ImageClient {
|
||||
@@ -48,10 +46,8 @@ public class ImageClientImpl implements ImageClient {
|
||||
@Override
|
||||
public String getImagePath() {
|
||||
var httpClient = HttpClient.newHttpClient();
|
||||
var httpGet = HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(URI.create("http://localhost:50005/image-path"))
|
||||
.build();
|
||||
var httpGet =
|
||||
HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50005/image-path")).build();
|
||||
|
||||
try {
|
||||
LOGGER.info("Sending request to fetch image path");
|
||||
|
||||
+2
-6
@@ -27,14 +27,10 @@ package com.iluwatar.api.gateway;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Encapsulates all of the information that mobile client needs to display a product.
|
||||
*/
|
||||
/** Encapsulates all of the information that mobile client needs to display a product. */
|
||||
@Getter
|
||||
@Setter
|
||||
public class MobileProduct {
|
||||
/**
|
||||
* The price of the product.
|
||||
*/
|
||||
/** The price of the product. */
|
||||
private String price;
|
||||
}
|
||||
|
||||
+1
-3
@@ -24,9 +24,7 @@
|
||||
*/
|
||||
package com.iluwatar.api.gateway;
|
||||
|
||||
/**
|
||||
* An interface used to communicate with the Price microservice.
|
||||
*/
|
||||
/** An interface used to communicate with the Price microservice. */
|
||||
public interface PriceClient {
|
||||
String getPrice();
|
||||
}
|
||||
|
||||
+3
-8
@@ -33,10 +33,7 @@ import java.net.http.HttpResponse.BodyHandlers;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* An adapter to communicate with the Price microservice.
|
||||
*/
|
||||
/** An adapter to communicate with the Price microservice. */
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PriceClientImpl implements PriceClient {
|
||||
@@ -49,10 +46,8 @@ public class PriceClientImpl implements PriceClient {
|
||||
@Override
|
||||
public String getPrice() {
|
||||
var httpClient = HttpClient.newHttpClient();
|
||||
var httpGet = HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(URI.create("http://localhost:50006/price"))
|
||||
.build();
|
||||
var httpGet =
|
||||
HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50006/price")).build();
|
||||
|
||||
try {
|
||||
LOGGER.info("Sending request to fetch price info");
|
||||
|
||||
Reference in New Issue
Block a user