在向节点js中的azure服务总线队列发送消息时,如何将内容类型指定为应用/json? [英] How to specify content type as application/json while sending message to azure service bus queue in node js?
本文介绍了在向节点js中的azure服务总线队列发送消息时,如何将内容类型指定为应用/json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@azure/service-bus
包和sendMessages
函数向队列发送消息,如here中所述。
当我发送一个Java脚本数组[{ name: "Albert Einstein", "company": "xyz" }]
时,它给出了一个错误TypeError: Provided value for 'message' must be of type ServiceBusMessage
。因此,在研究发现它添加了正文键后,例如[body:{name: "Albert Einstein", "company": "xyz"}]
。但这会插入内容类型为应用程序/XML的记录。有没有什么方法可以指定内容类型:应用程序/json?
推荐答案
可以指定如下contentType
:
const messages = [
{
body: { "name": "Albert Einstein", "company": "xyz"},
contentType: "application/json"
}
]
这篇关于在向节点js中的azure服务总线队列发送消息时,如何将内容类型指定为应用/json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文