|
| 1 | +/** |
| 2 | + * The MIT License |
| 3 | + * Copyright (c) 2014 Ilkka Seppälä |
| 4 | + * |
| 5 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | + * of this software and associated documentation files (the "Software"), to deal |
| 7 | + * in the Software without restriction, including without limitation the rights |
| 8 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | + * copies of the Software, and to permit persons to whom the Software is |
| 10 | + * furnished to do so, subject to the following conditions: |
| 11 | + * |
| 12 | + * The above copyright notice and this permission notice shall be included in |
| 13 | + * all copies or substantial portions of the Software. |
| 14 | + * |
| 15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | + * THE SOFTWARE. |
| 22 | + */ |
| 23 | +package com.iluwatar.api.gateway; |
| 24 | + |
| 25 | +import org.springframework.boot.SpringApplication; |
| 26 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 27 | + |
| 28 | +/** |
| 29 | + * With the Microservices pattern, a client may need data from multiple different microservices. |
| 30 | + * If the client called each microservice directly, that could contribute to longer load times, |
| 31 | + * since the client would have to make a network request for each microservice called. Moreover, |
| 32 | + * having the client call each microservice directly ties the client to that microservice - if the |
| 33 | + * internal implementations of the microservices change (for example, if two microservices are |
| 34 | + * combined sometime in the future) or if the location (host and port) of a microservice changes, |
| 35 | + * then every client that makes use of those microservices must be updated. |
| 36 | + * |
| 37 | + * <p> |
| 38 | + * The intent of the API Gateway pattern is to alleviate some of these issues. In the API Gateway |
| 39 | + * pattern, an additional entity (the API Gateway) is placed between the client and the |
| 40 | + * microservices. The job of the API Gateway is to aggregate the calls to the microservices. |
| 41 | + * Rather than the client calling each microservice individually, the client calls the API Gateway |
| 42 | + * a single time. The API Gateway then calls each of the microservices that the client needs. |
| 43 | + * |
| 44 | + * <p> |
| 45 | + * This implementation shows what the API Gateway pattern could look like for an e-commerce site. |
| 46 | + * The {@link ApiGateway} makes calls to the Image and Price microservices using the |
| 47 | + * {@link ImageClientImpl} and {@link PriceClientImpl} respectively. Customers viewing the site on a |
| 48 | + * desktop device can see both price information and an image of a product, so the {@link ApiGateway} |
| 49 | + * calls both of the microservices and aggregates the data in the {@link DesktopProduct} model. |
| 50 | + * However, mobile users only see price information; they do not see a product image. For mobile |
| 51 | + * users, the {@link ApiGateway} only retrieves price information, which it uses to populate the |
| 52 | + * {@link MobileProduct}. |
| 53 | + */ |
| 54 | +@SpringBootApplication |
| 55 | +public class App { |
| 56 | + |
| 57 | + /** |
| 58 | + * Program entry point |
| 59 | + * |
| 60 | + * @param args |
| 61 | + * command line args |
| 62 | + */ |
| 63 | + public static void main(String[] args) { |
| 64 | + SpringApplication.run(App.class, args); |
| 65 | + } |
| 66 | +} |
0 commit comments