gpt4 book ai didi

node.js - 如何在 Node js中将消息发送到azure服务总线队列时指定内容类型为application/json?

转载 作者:行者123 更新时间:2023-12-04 17:21:02 24 4
gpt4 key购买 nike

我正在使用 @azure/service-bus 向队列发送消息包和sendMessages功能如 here 中提到的。当我发送 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"
}
]

请引用ServiceBusMessage :

enter image description here

关于node.js - 如何在 Node js中将消息发送到azure服务总线队列时指定内容类型为application/json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66226741/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com