MCP B修改服务
微服务后端,用于处理数据修改,特别是通过与服务A通信创建新订单和减少库存。
特点
- 创建订单接受新订单请求。
- 库存管理与查询服务(MCP A)通信,以检查和减少库存。
- 日志记录简单的日志记录每个传入的订单。
系统要求
- (版本 14 或更高版本)
- NPM(通常与 Node.js 一起安装)
安装
- 克隆此仓库或下载源代码。
- 打开终端并导航到此项目目录。
- 安装依赖项:
npm install配置
此服务使用以下环境变量(可选,默认可用):
PORT此服务器的端口(默认:3002)- MCP A URL 假设运行在
http://localhost:3001
应用程序将默认运行 http://localhost:3002.
运行应用程序
要在开发模式下运行服务器:
npm start终端输出将显示:
MCP B Modify Server berjalan di port 3002API Endpoint列表
1.创建新订单
创建新订单并触发服务A的库存减少。
- 统一资源定位符:
/api/v1/new-order
- 方法:
POST
- 标头:
Content-Type: application/json
- 车身参数:
| 密钥 | 类型 | 描述 |
|---|---|---|
product | 字符串 | 产品名称 (必填) |
quantity | Number | 项目数量 (可选, 默认: 1) |
- Contoh请求:
{
"product": "Laptop",
"quantity": 2
}- 成功反应的例子 (201):
{
"message": "Pesanan Laptop berhasil dicatat.",
"orderId": 1,
"status": "Processing",
"stockUpdated": 48
}- 失败的响应示例 (400):
{
"message": "Gagal update stok: Stock not sufficient"
}Struktur项目
├── modifyServer.js # Entry point aplikasi
├── package.json # Dependencies dan scripts
├── .gitignore # File yang diabaikan git
├── README.md # Dokumentasi project
└── node_modules/ # Pustaka/library (jangan di-commit)附加注释
- 确保 MCP A(查询服务) 走在港口
3001在执行请求订单之前,因为该服务依赖它来更新库存。
