Azure.Messaging.ServiceBus (.NET)
使用 .NET 建構 Azure Service Bus 訊息解決方案
開發者在分散式 .NET 應用程式中難以實現可靠的訊息傳遞和發布/訂閱模式。此技能提供完整的 Azure Service Bus SDK 指導,包含可直接用於生產環境的程式碼範例。
下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「Azure.Messaging.ServiceBus (.NET)」。 傳送訊息到 Azure Service Bus 佇列
預期結果:
- 使用 DefaultAzureCredential 顯示 ServiceBusClient 建立的程式碼範例
- 針對目標佇列的 ServiceBusSender 初始化
- 包含內容內容的 ServiceBusMessage 建構
- 具有適當處置模式的非同步 SendMessageAsync 呼叫
正在使用「Azure.Messaging.ServiceBus (.NET)」。 在背景處理訊息
預期結果:
- 具有 AutoCompleteMessages 和 MaxConcurrentCalls 的 ServiceBusProcessor 設定
- 具有 try/catch 和訊息結算的 ProcessMessageAsync 處理常式
- 用於錯誤記錄和診斷的 ProcessErrorAsync 處理常式
- StartProcessingAsync 和 StopProcessingAsync 生命週期管理
安全審計
安全This is a prompt-only documentation skill with no executable code. Static analysis correctly identified zero security risks. The skill provides legitimate Azure Service Bus SDK guidance including authentication best practices (DefaultAzureCredential), proper resource disposal patterns, and standard messaging workflows. No suspicious patterns, injection attempts, or malicious intent detected.
品質評分
你能建構什麼
企業訊息佇列整合
使用 Service Bus 佇列在微服務間建立可靠的非同步通訊,具備適當的錯誤處理和訊息結算機制。
使用主題的事件驅動架構
實現發布/訂閱模式,將事件廣播到不同服務的多個訂閱者。
使用工作階段的順序處理
使用基於工作階段的接收器以嚴格順序處理相關訊息,適用於訂單履行工作流程等情境。
試試這些提示
Show me how to send and receive a single message from an Azure Service Bus queue using .NET with DefaultAzureCredential authentication.
Create a ServiceBusProcessor that handles messages from a queue with concurrent calls, proper error handling, and automatic message completion.
Implement session-based message processing in .NET that maintains FIFO order for related messages using ServiceBusSessionReceiver.
Set up Azure Service Bus topics with multiple subscriptions and SQL filters to route messages to different subscribers based on message properties.
最佳實務
- 在生產環境中使用 DefaultAzureCredential 進行身分驗證,而非連線字串
- 將 ServiceBusClient、發送器和接收器重複使用為單一執行個體 - 它們是執行緒安全的,設計用於長期使用
- 一律使用 await using 陳述式處置資源,以確保正確的連線清理
避免
- 為每則訊息建立新的 ServiceBusClient 執行個體 - 會導致連線耗盡和效能下降
- 在用戶端應用程式中使用具有共用存取金鑰的連線字串 - 會暴露憑證且缺乏細粒度存取控制
- 忽略訊息鎖定持續時間 - 如果處理時間超過鎖定逾時,訊息可能會被放棄並重新遞送