Resolves checkstyle errors for api-gateway, lazy-loading, leader-election (#1066)
* Reduces checkstyle errors in lazy-loading * Reduces checkstyle errors in leader-election * Reduces checkstyle errors in api-gateway
This commit is contained in:
committed by
Ilkka Seppälä
parent
7f06f3b78c
commit
eae09fc07e
@ -23,12 +23,11 @@
|
||||
|
||||
package com.iluwatar.api.gateway;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* The ApiGateway aggregates calls to microservices based on the needs of the individual clients.
|
||||
*/
|
||||
@ -42,7 +41,8 @@ public class ApiGateway {
|
||||
private PriceClient priceClient;
|
||||
|
||||
/**
|
||||
* Retrieves product information that desktop clients need
|
||||
* Retrieves product information that desktop clients need.
|
||||
*
|
||||
* @return Product information for clients on a desktop
|
||||
*/
|
||||
@RequestMapping(path = "/desktop", method = RequestMethod.GET)
|
||||
@ -54,7 +54,8 @@ public class ApiGateway {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves product information that mobile clients need
|
||||
* Retrieves product information that mobile clients need.
|
||||
*
|
||||
* @return Product information for clients on a mobile device
|
||||
*/
|
||||
@RequestMapping(path = "/mobile", method = RequestMethod.GET)
|
||||
|
@ -27,39 +27,36 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* With the Microservices pattern, a client may need data from multiple different microservices.
|
||||
* If the client called each microservice directly, that could contribute to longer load times,
|
||||
* since the client would have to make a network request for each microservice called. Moreover,
|
||||
* having the client call each microservice directly ties the client to that microservice - if the
|
||||
* internal implementations of the microservices change (for example, if two microservices are
|
||||
* combined 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.
|
||||
* With the Microservices pattern, a client may need data from multiple different microservices. If
|
||||
* the client called each microservice directly, that could contribute to longer load times, since
|
||||
* the client would have to make a network request for each microservice called. Moreover, having
|
||||
* the client call each microservice directly ties the client to that microservice - if the internal
|
||||
* implementations of the microservices change (for example, if two microservices are combined
|
||||
* 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
|
||||
* 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>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 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} model.
|
||||
* However, mobile users only see price information; they do not see a product image. For mobile
|
||||
* users, the {@link ApiGateway} only retrieves price information, which it uses to populate the
|
||||
* {@link MobileProduct}.
|
||||
* <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}
|
||||
* model. However, mobile users only see price information; they do not see a product image. For
|
||||
* mobile users, the {@link ApiGateway} only retrieves price information, which it uses to populate
|
||||
* the {@link MobileProduct}.
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args
|
||||
* command line args
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(App.class, args);
|
||||
|
@ -28,12 +28,12 @@ package com.iluwatar.api.gateway;
|
||||
*/
|
||||
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,7 +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();
|
||||
|
@ -29,17 +29,16 @@ import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.net.http.HttpResponse.BodyHandlers;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* An adapter to communicate with the Image microservice
|
||||
* An adapter to communicate with the Image microservice.
|
||||
*/
|
||||
@Component
|
||||
public class ImageClientImpl implements ImageClient {
|
||||
/**
|
||||
* Makes a simple HTTP Get request to the Image microservice
|
||||
*
|
||||
* Makes a simple HTTP Get request to the Image microservice.
|
||||
*
|
||||
* @return The path to the image
|
||||
*/
|
||||
@Override
|
||||
@ -47,7 +46,8 @@ public class ImageClientImpl implements ImageClient {
|
||||
String response = null;
|
||||
|
||||
HttpClient httpClient = HttpClient.newHttpClient();
|
||||
HttpRequest httpGet = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50005/image-path")).build();
|
||||
HttpRequest httpGet =
|
||||
HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50005/image-path")).build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> httpResponse = httpClient.send(httpGet, BodyHandlers.ofString());
|
||||
|
@ -28,7 +28,7 @@ package com.iluwatar.api.gateway;
|
||||
*/
|
||||
public class MobileProduct {
|
||||
/**
|
||||
* The price of the product
|
||||
* The price of the product.
|
||||
*/
|
||||
private String price;
|
||||
|
||||
|
@ -24,7 +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();
|
||||
|
@ -29,17 +29,16 @@ import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.net.http.HttpResponse.BodyHandlers;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* An adapter to communicate with the Price microservice
|
||||
* An adapter to communicate with the Price microservice.
|
||||
*/
|
||||
@Component
|
||||
public class PriceClientImpl implements PriceClient {
|
||||
/**
|
||||
* Makes a simple HTTP Get request to the Price microservice
|
||||
*
|
||||
* Makes a simple HTTP Get request to the Price microservice.
|
||||
*
|
||||
* @return The price of the product
|
||||
*/
|
||||
@Override
|
||||
@ -48,7 +47,8 @@ public class PriceClientImpl implements PriceClient {
|
||||
String response = null;
|
||||
|
||||
HttpClient httpClient = HttpClient.newHttpClient();
|
||||
HttpRequest httpGet = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50006/price")).build();
|
||||
HttpRequest httpGet =
|
||||
HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:50006/price")).build();
|
||||
|
||||
try {
|
||||
HttpResponse<String> httpResponse = httpClient.send(httpGet, BodyHandlers.ofString());
|
||||
|
@ -20,5 +20,4 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
server.port=50004
|
Reference in New Issue
Block a user