小编bip*_*pan的帖子

API Gateway 上的数据聚合

我正在研究微服务架构,我想聚合来自两个微服务的数据。

例如,Frontend 调用 API Gateway,API Gateway 调用两个微服务 Customer 和 Order 微服务。客户微服务返回客户详细信息,订单微服务返回客户所有订购的产品。

这是使用 Ocelot 或 Azure API 管理从两个微服务聚合后 API 网关返回的格式。

格式 1

{ 
   "Customers":[ 
      { 
         "customerId":1001,
         "customerName":"Tom"
      },
      { 
         "customerId":1002,
         "customerName":"Jerry"
      }
   ],
   "Orders":[ 
      { 
         "CustomerId":1001,
         "Orders":[ 
            { 
               "ProductId":"PRO1",
               "ProductName":"Books"
            },
            { 
               "ProductId":"PRO2",
               "ProductName":"Pens"
            }
         ]
      },
      { 
         "CustomerId":1002,
         "Orders":[ 
            { 
               "ProductId":"PRO3",
               "ProductName":"Pencils"
            },
            { 
               "ProductId":"PRO4",
               "ProductName":"Toys"
            }
         ]
      }
   ]
}
Run Code Online (Sandbox Code Playgroud)

我想要的格式是格式 2。

格式 2

{
   "OrderDetails":[
      {
         "customerId":1001,
         "customerName":"Tom",
         "Orders":[
            {
               "ProductId":"PRO1",
               "ProductName":"Books"
            },
            {
               "ProductId":"PRO2",
               "ProductName":"Pens"
            }
         ] …
Run Code Online (Sandbox Code Playgroud)

azure-api-management microservices aws-api-gateway api-gateway ocelot

12
推荐指数
1
解决办法
5385
查看次数