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:
Ilkka Seppälä
2025-03-29 19:34:27 +02:00
committed by GitHub
parent 371439aeaa
commit 0ca162a55c
1863 changed files with 14403 additions and 17632 deletions
@@ -38,6 +38,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>6.2.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -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.
@@ -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}
@@ -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;
}
@@ -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();
}
@@ -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");
@@ -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;
}
@@ -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();
}
@@ -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");
@@ -33,28 +33,21 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
/**
* Test API Gateway Pattern
*/
/** Test API Gateway Pattern */
class ApiGatewayTest {
@InjectMocks
private ApiGateway apiGateway;
@InjectMocks private ApiGateway apiGateway;
@Mock
private ImageClient imageClient;
@Mock private ImageClient imageClient;
@Mock
private PriceClient priceClient;
@Mock private PriceClient priceClient;
@BeforeEach
void setup() {
MockitoAnnotations.openMocks(this);
}
/**
* Tests getting the data for a desktop client
*/
/** Tests getting the data for a desktop client */
@Test
void testGetProductDesktop() {
var imagePath = "/product-image.png";
@@ -68,9 +61,7 @@ class ApiGatewayTest {
assertEquals(imagePath, desktopProduct.getImagePath());
}
/**
* Tests getting the data for a mobile client
*/
/** Tests getting the data for a mobile client */
@Test
void testGetProductMobile() {
var price = "20";
@@ -38,6 +38,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>6.2.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -28,10 +28,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Exposes the Image microservice's endpoints.
*/
/** Exposes the Image microservice's endpoints. */
@Slf4j
@RestController
public class ImageController {
@@ -24,13 +24,11 @@
*/
package com.iluwatar.image.microservice;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Image Rest Controller
*/
import org.junit.jupiter.api.Test;
/** Test for Image Rest Controller */
class ImageControllerTest {
@Test
-11
View File
@@ -34,17 +34,6 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>microservices-api-gateway</artifactId>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<type>pom</type>
<version>3.2.4</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>image-microservice</module>
<module>price-microservice</module>
@@ -38,6 +38,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>6.2.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -28,10 +28,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Exposes the Price microservice's endpoints.
*/
/** Exposes the Price microservice's endpoints. */
@RestController
@RequiredArgsConstructor
public class PriceController {
@@ -24,9 +24,7 @@
*/
package com.iluwatar.price.microservice;
/**
* Service to get a product's price.
*/
/** Service to get a product's price. */
public interface PriceService {
/**
@@ -27,16 +27,12 @@ package com.iluwatar.price.microservice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Service
@Slf4j
public class PriceServiceImpl implements PriceService {
/**
* {@inheritDoc}
*/
/** {@inheritDoc} */
@Override
public String getPrice() {
LOGGER.info("Successfully found price info");
@@ -24,13 +24,11 @@
*/
package com.iluwatar.price.microservice;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Price Rest Controller
*/
import org.junit.jupiter.api.Test;
/** Test for Price Rest Controller */
class PriceControllerTest {
@Test
@@ -24,13 +24,11 @@
*/
package com.iluwatar.price.microservice;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test for Price Service
*/
import org.junit.jupiter.api.Test;
/** Test for Price Service */
class PriceServiceTest {
@Test