* translate Abstract Document documentation in french * translate Abstract Document documentation in french for issue #2278 * french translation of abstract factory * French translation for active-object * translate Abstract Document documentation in french * translate Abstract Document documentation in french for issue #2278 * french translation of abstract factory * French translation for active-object * tranlate to french: acyclic-visitore, adapter, aggregator-microservice, ambassador, api-gateway, arrange-act-assert, async-method-invocation, balking, bridge.
title, category, language, tag
| title | category | language | tag | |||
|---|---|---|---|---|---|---|
| Aggregator Microservices | Architectural | fr |
|
Intention
L'utilisateur fait un appel unique au service d'agrégation, et ce dernier appelle ensuite chaque microservice approprié.
Explication
Exemple concret
Notre marché en ligne a besoin d'informations sur les produits et leur stock actuel. Elle fait appel à un service d'agrégation qui, à son tour, appelle le microservice d'information sur les produits et le microservice d'inventaire des produits et renvoie les informations combinées.
En clair
Aggregator Microservice collecte des éléments de données provenant de divers microservices et renvoie un agrégat pour traitement..
Stack Overflow dit
Aggregator Microservice invoque plusieurs services pour réaliser la fonctionnalité requise par l'application.
Exemple de programme
Commençons par le modèle de données. Voici notre Product.
public class Product {
private String title;
private int productInventories;
// getters and setters ->
...
}
Ensuite, nous pouvons présenter notre microservice Aggregator. Il contient les clients ProductInformationClient et
ProductInventoryClient pour appeler les microservices respectifs.
@RestController
public class Aggregator {
@Resource
private ProductInformationClient informationClient;
@Resource
private ProductInventoryClient inventoryClient;
@RequestMapping(path = "/product", method = RequestMethod.GET)
public Product getProduct() {
var product = new Product();
var productTitle = informationClient.getProductTitle();
var productInventory = inventoryClient.getProductInventories();
//Fallback to error message
product.setTitle(requireNonNullElse(productTitle, "Error: Fetching Product Title Failed"));
//Fallback to default error inventory
product.setProductInventories(requireNonNullElse(productInventory, -1));
return product;
}
}
Voici l'essentiel de la mise en œuvre du microservice d'information. Le microservice dInventory est similaire, il renvoie simplement l'inventaire.
@RestController
public class InformationController {
@RequestMapping(value = "/information", method = RequestMethod.GET)
public String getProductTitle() {
return "The Product Title.";
}
}
L'appel à notre API REST Aggregator renvoie les informations sur le produit.
curl http://localhost:50004/product
{"title":"The Product Title.","productInventories":5}
Class diagram
Application
Utilisez le modèle de microservices agrégateur lorsque vous avez besoin d'une API unifiée pour différents microservices, quel que soit l'appareil client.
