Skip to content

Commit 31b7df2

Browse files
authored
translation: Add aggregator microservices pattern translation iluwatar#2288 (iluwatar#2582)
* [Translate, Vietnamese] (Add) aggregator microservices pattern translation * [Translate, Vietnamese] (Fix) comment suggestions
1 parent 845fa9d commit 31b7df2

File tree

1 file changed

+102
-0
lines changed
  • localization/vi/aggregator-microservices

1 file changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: Microservices Tổng Hợp
3+
category: Architectural
4+
language: vi
5+
tag:
6+
- Cloud distributed
7+
- Decoupling
8+
- Microservices
9+
---
10+
11+
## Mục Đích
12+
Người dùng chỉ cần thực hiện một lần gọi duy nhất đến dịch vụ tổng hợp, sau đó dịch vụ tổng hợp sẽ gọi dịch vụ con tương ứng.
13+
14+
## Giải Thích
15+
16+
Ví dụ thực tế
17+
18+
> Trang web thị trường của chúng ta cần thông tin về sản phẩm và tồn kho hiện tại của chúng. Nó thực hiện gọi đến dịch vụ tổng hợp, sau đó dịch vụ tổng hợp gọi dịch vụ thông tin sản phẩm và dịch vụ tồn kho sản phẩm, cuối cùng trả lại thông tin kết hợp.
19+
20+
## Nói đơn giản hơn
21+
22+
> Microservices Tổng Hợp thu thập các phần dữ liệu từ các dịch vụ con khác nhau và trả về một tổng hợp để xử lý.
23+
24+
Theo Stack Overflow
25+
26+
> Microservices Tổng Hợp gọi nhiều dịch vụ để đạt được chức năng được yêu cầu bởi ứng dụng.
27+
28+
**Mã nguồn mẫu**
29+
30+
Hãy bắt đầu từ mô hình dữ liệu. Đây là lớp `Product` của chúng ta.
31+
32+
```java
33+
public class Product {
34+
private String title;
35+
private int productInventories;
36+
// getters and setters ->
37+
...
38+
}
39+
```
40+
41+
Tiếp theo, chúng ta có thể giới thiệu Microservices `Aggregator` của chúng ta. Nó chứa các khách hàng `ProductInformationClient`
42+
`ProductInventoryClient` để gọi các dịch vụ con tương ứng.
43+
44+
```java
45+
@RestController
46+
public class Aggregator {
47+
48+
@Resource
49+
private ProductInformationClient informationClient;
50+
51+
@Resource
52+
private ProductInventoryClient inventoryClient;
53+
54+
@RequestMapping(path = "/product", method = RequestMethod.GET)
55+
public Product getProduct() {
56+
57+
var product = new Product();
58+
var productTitle = informationClient.getProductTitle();
59+
var productInventory = inventoryClient.getProductInventories();
60+
61+
//Fallback to error message
62+
product.setTitle(requireNonNullElse(productTitle, "Error: Fetching Product Title Failed"));
63+
64+
//Fallback to default error inventory
65+
product.setProductInventories(requireNonNullElse(productInventory, -1));
66+
67+
return product;
68+
}
69+
}
70+
```
71+
72+
Dưới đây là bản thể của việc triển khai dịch vụ thông tin sản phẩm. Dịch vụ tồn kho cũng tương tự như thế, nó chỉ trả về số lượng tồn kho.
73+
74+
```java
75+
@RestController
76+
public class InformationController {
77+
@RequestMapping(value = "/information", method = RequestMethod.GET)
78+
public String getProductTitle() {
79+
return "The Product Title.";
80+
}
81+
}
82+
```
83+
84+
Bây giờ, việc gọi `Aggregator` API REST của chúng ta sẽ trả về thông tin sản phẩm.
85+
86+
```bash
87+
curl http://localhost:50004/product
88+
{"title":"The Product Title.","productInventories":5}
89+
```
90+
91+
## Sơ Đồ Lớp
92+
![alt text](../../../aggregator-microservices/aggregator-service/etc/aggregator-service.png "Aggregator Microservice")
93+
94+
95+
## Các Trường Hợp Sử Dụng
96+
Sử dụng mẫu Microservices Tổng Hợp khi bạn cần một API chung cho các dịch vụ Microservices khác nhau, bất kể thiết bị của khách hàng.
97+
98+
## Người Đóng Góp
99+
100+
* [Microservice Design Patterns](http://web.archive.org/web/20190705163602/http://blog.arungupta.me/microservice-design-patterns/)
101+
* [Microservices Patterns: With examples in Java](https://www.amazon.com/gp/product/1617294543/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=javadesignpat-20&creative=9325&linkCode=as2&creativeASIN=1617294543&linkId=8b4e570267bc5fb8b8189917b461dc60)
102+
* [Architectural Patterns: Uncover essential patterns in the most indispensable realm of enterprise architecture](https://www.amazon.com/gp/product/B077T7V8RC/ref=as_li_qf_asin_il_tl?ie=UTF8&tag=javadesignpat-20&creative=9325&linkCode=as2&creativeASIN=B077T7V8RC&linkId=c34d204bfe1b277914b420189f09c1a4)

0 commit comments

Comments
 (0)