问题描述
我正在使用 here 中提到的 @azure/service-bus
包和 sendMessages
函数向队列发送消息。
当我发送一个 javascript 数组 [{ name: "Albert Einstein","company": "xyz" }]
时,它给出了一个错误 TypeError: Provided value for 'message' must be of type ServiceBusMessage
。因此,经过研究发现它添加了 body 键,例如[body:{name: "Albert Einstein","company": "xyz"}]
。但这会插入内容类型为 application/xml 的记录。有什么办法可以指定 content-type:application/json 吗?
解决方法
您可以指定 contentType
如下:
const messages = [
{
body: { "name": "Albert Einstein","company": "xyz"},contentType: "application/json"
}
]