You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Service Bus批量发送消息合并为单条问题求助

问题原因及解决方案

你的问题出在两个关键地方:API端点错误和Content-Type头不匹配,导致Service Bus把整个JSON数组当成了单条消息的Body,而非批量消息集合。

具体问题分析

  1. 端点错误:你使用的/messages端点是用于发送单条消息的,即便传入JSON数组,它也会将整个数组作为单条消息的内容处理,不会拆分多条。批量发送必须使用专门的/messages/batch端点。
  2. Content-Type不匹配:批量JSON消息对应的Content-Type应为application/vnd.microsoft.servicebus.json-batch,而非你当前使用的application/vnd.microsoft.servicebus.json,这个请求头用于告知Service Bus如何解析请求体格式。

另外,你调整的TimeToLive格式也需修正:正确格式是ISO 8601时长字符串(例如PT40S表示40秒),而非0.00:00:40。

修正后的curl命令

curl -X POST "https://{myServiceNamespace}.servicebus.windows.net/{name_of_my_queue}/messages/batch" -v \
-H "Authorization: Bearer {my_token}" \
-H "Content-Type: application/vnd.microsoft.servicebus.json-batch" \
-d '[{"Body":"This is the first message","BrokerProperties":{"Label":"M1","TimeToLive":"PT40S"}},{"Body":"This is the second message","BrokerProperties":{"Label":"M2"},"UserProperties":{"Priority":"Low"}},{"Body":"This is the third message","BrokerProperties":{"Label":"M3"},"UserProperties":{"Priority":"Medium","Customer":"ABC"}}]'

验证要点

  • 确认端点末尾为/messages/batch
  • Content-Type严格使用application/vnd.microsoft.servicebus.json-batch
  • TimeToLive采用ISO 8601格式(如PT1M表示1分钟,PT1H表示1小时)

内容的提问来源于stack exchange,提问作者jsanmarb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 17:36:06