用Claude Code设计EC订单的Azure Service Bus
把EC订单、库存、邮件、DLQ、重复检测和重试规则拆成Azure Service Bus表。
EC店铺里,订单页面、库存CSV、发货请求、邮件日志和重试记录常常分散。明明只是邮件失败,却把整个订单事件重发,库存就可能被扣两次。本文把 Azure Service Bus 的 queue、topic、DLQ 和 duplicate detection 变成一张订单运维表。
EC订单流程在哪里出错
- 不要把订单确认、库存预留、发货请求、邮件发送和重试混进一个queue。
- 一个订单要分给库存、发货、邮件和分析时,用topic更清楚。
- MessageId要由订单ID、明细ID和动作组成,保持稳定。
- dead-letter queue是排查桌,不是盲目重发按钮。
- Claude Code负责起草表格;支付、退款、个人信息和上线批准由人确认。
The Microsoft documentation for Service Bus overview, queues, topics, and subscriptions, dead-letter queues, duplicate detection, message transfers, and pricing tiers is the source base. The internal Azure memo pattern is also related to the Azure OpenAI privacy memo.
Claude Code负责什么,人负责什么
EC店铺里,订单页面、库存CSV、发货请求、邮件日志和重试记录常常分散。明明只是邮件失败,却把整个订单事件重发,库存就可能被扣两次。本文把 Azure Service Bus 的 queue、topic、DLQ 和 duplicate detection 变成一张订单运维表。 Claude Code should read column names, event names, retry samples, and DLQ reason text. It should not receive card data, full address text, refund judgment, or credentials. The output should be a table with event name, input columns, queue or topic, subscription, MessageId, DLQ owner, retry condition, and human review.
Humans keep payment state, refund permission, privacy policy, stock finalization, warehouse contract, apology text, and release approval. This split matters because a technically valid retry can still be a business mistake. The table makes the stop point visible before production.
三个Use case
Use case 1
订单确认会触发多个动作。输入: 订单CSV、订单ID、明细ID、SKU、数量、支付状态、邮件标记。输出: topic:orders,以及库存、发货、邮件、分析subscription。人工确认: 未支付、预售、组合商品、礼品、手工库存调整、邮件文案。
Use case 2
库存预留需要稳定的业务键。输入: 订单ID、明细ID、SKU、数量、reserve动作、发送日志。输出: MessageId表,例如订单ID加明细ID加reserve。人工确认: 数量变更、取消、重新下单、组合拆分、库存回滚。
Use case 3
DLQ必须让运营也能读懂。输入: reason、description、订单ID、SKU、失败次数、时间、备注。输出: 自动重试、修正后重试、订单保留、退款确认、开发调查。人工确认: 客户通知、退款、库存差异、仓库联系、重发权限。
可复制的提示词
You are preparing an Azure Service Bus design memo for an EC store.
Inputs: order CSV columns, inventory CSV columns, event names, retry logs, DLQ reason samples, and planned Azure tier.
Output:
1. Event table with eventName, input columns, queue or topic, subscription, MessageId, and DLQ owner.
2. Human review table for payment, refund, personal data, stock finalization, customer notice, and resend approval.
3. MessageId naming rules based on order id, line item id, and action.
4. DLQ classification: auto retry, fix then retry, hold order, refund review, engineering investigation.
5. One first action that can be done in 30 minutes.
Rules: do not put card data or full address text in messages. Do not blindly resend every DLQ message.
检查代码
const events = [
{ type: "order.accepted", orderId: "ORD-1001", lineItemId: "1", sku: "TSHIRT-M", quantity: 2, action: "accept" },
{ type: "inventory.reserve", orderId: "ORD-1001", lineItemId: "1", sku: "TSHIRT-M", quantity: 2, action: "reserve" },
{ type: "inventory.reserve", orderId: "ORD-1001", lineItemId: "1", sku: "TSHIRT-M", quantity: 2, action: "reserve" },
{ type: "mail.send", orderId: "ORD-1001", lineItemId: "", sku: "", quantity: 0, action: "confirmation" },
{ type: "inventory.reserve", orderId: "", lineItemId: "2", sku: "MUG-BLUE", quantity: 1, action: "reserve" },
{ type: "shipping.requested", orderId: "ORD-1002", lineItemId: "1", sku: "BAG-BK", quantity: 1, action: "ship" }
];
function routeEvent(event) {
if (event.type === "order.accepted") {
return {
entity: "topic:orders",
messageId: event.orderId + ":accepted",
reason: "fan out to inventory, shipping, mail, and analytics subscriptions"
};
}
if (event.type === "inventory.reserve") {
return {
entity: "queue:inventory-reserve",
messageId: event.orderId + ":" + event.lineItemId + ":reserve",
reason: "one stock reservation worker should own this line item"
};
}
if (event.type === "mail.send") {
return {
entity: "queue:mail-send",
messageId: event.orderId + ":" + event.action,
reason: "mail can retry without touching stock"
};
}
return {
entity: "needs-design-review",
messageId: event.orderId + ":" + event.type,
reason: "route is not documented yet"
};
}
const seen = new Set();
const findings = [];
for (const event of events) {
const route = routeEvent(event);
if (!event.orderId) {
findings.push({
type: "missing-order-id",
eventType: event.type,
fix: "do not send this message until the order id is present"
});
}
if (seen.has(route.messageId)) {
findings.push({
type: "duplicate-message-id",
eventType: event.type,
messageId: route.messageId,
fix: "keep the same MessageId for sender retry, but make the handler idempotent"
});
}
if (route.entity === "needs-design-review") {
findings.push({
type: "unknown-route",
eventType: event.type,
fix: "decide queue, topic subscription, DLQ owner, and retry rule before release"
});
}
seen.add(route.messageId);
}
console.table(findings);
if (findings.length > 0) process.exitCode = 1;
Pitfall: 常见错误
The first cause is one queue for every action. The fix is to use a topic for order accepted and separate queues or subscriptions for inventory, shipping, and mail. This prevents a mail retry from touching stock again.
The second cause is random MessageId generation. The fix is to generate the id from order id, line item id, and action before sending. Duplicate detection can only help inside the configured window when the id stays stable.
The third cause is blind DLQ resend. The fix is to classify each reason into auto retry, fix then retry, hold order, refund review, or engineering investigation. Messages that affect customers or refunds need human review.
The fourth cause is ignoring tier differences. The fix is to check whether topics, transactions, de-duplication, or sessions are required before choosing Basic, Standard, or Premium.
常见问题
Q. Should every EC event be a topic? A. No. Topic is useful when one event fans out. A queue is clearer when one worker owns one task such as inventory reservation or mail send.
Q. Does duplicate detection remove all double stock moves? A. No. It helps when MessageId is stable. The handler should still check whether the line item was already processed.
Q. Who should read DLQ? A. Operations and developers. EC failures can involve customer notice, refund, stock gap, and warehouse contact.
Q. What should message body contain? A. Prefer order id, line item id, SKU, quantity, and reference id. Review personal data and logging policy before adding sensitive text.
咨询路径
对EC团队来说,价值不在云架构图,而在少扣错库存、少延迟发货、少客服工单。带上CSV列、三条失败消息和当前重试步骤,到咨询页面整理即可。 Use Claude Code training and consultation when the team needs help turning order CSV, inventory CSV, retry logs, and release approval into a workflow.
我验证了什么
我查看了 Microsoft Learn 中 Service Bus overview、queues/topics/subscriptions、DLQ、duplicate detection、transfers 和 pricing tiers。也本地运行了检查代码,确认能发现缺少订单ID、重复MessageId和未知route。第一步是做一张订单、库存、邮件、重试表。
相关文章
用Claude Code构建电商商店:Next.js、Stripe Checkout与库存管理
用Claude Code实现电商核心流程:商品、购物车、库存、Stripe Checkout、Webhook、后台、SEO、数据分析与售后。
零售小店用 Claude Code 批量生成 POP、传单文案和陈列备注的实操步骤
面向零售店店长和导购。用 Claude Code 给 POP、传单文案、陈列备注提速,附可复制的提示词模板和一段校验脚本。
用 Claude Code 实现 Service Worker:缓存、更新与离线 UX
讲清 Service Worker、缓存失效、更新生命周期、离线 UX,并提供可复制运行的 Claude Code 示例。
免费 PDF: Claude Code 速查表
输入邮箱即可获取一页 PDF,整理常用命令、审查习惯和安全工作流。
我们会妥善保护你的信息,不发送垃圾邮件。
让 Claude Code 真正进入可验证的工作流
先用免费 PDF 固定基础,再用 Gumroad 教材复用工作流;如果涉及团队导入、权限或收入路径,可以直接咨询。
关于作者
Masa
专注 Claude Code 实务流程、团队导入和内容转化的工程师。