【发布时间】:2022-11-07 07:11:34
【问题描述】:
我正在开发一个以 Azure 服务总线主题作为其输出的 TypeScript Azure 函数。我可以毫无问题地使用它发送消息,但我无法将任何元数据设置为消息的自定义属性。
我尝试使用与 Service Bus Javascript SDK 中的ServiceBusMessage 具有相同接口的对象,如下所示:
import { AzureFunction, Context, HttpRequest } from "@azure/functions";
const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest
): Promise<void> {
const message = {
body: "my message content",
applicationProperties: { key: "value" },
};
context.bindings.myTopic = message;
};
export default httpTrigger;
但是message 是按原样发送的,applicationProperties 不考虑在内。我在服务总线资源管理器的 Azure 门户上看不到它们。消息的内容将是 message 对象的 JSON 版本。
我已经尝试使用扩展包 3 和 4,但没有成功。
我正在使用这个function.json 文件:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": ["get", "post"]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "myTopic",
"type": "serviceBus",
"queueName": "myTopic",
"connection": "SERVICE_BUS_CONNECTION_STRING",
"direction": "out"
}
],
"scriptFile": "../dist/servicebus-writer/index.js"
}
而这个host.json 文件:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.3.0, 4.0.0)"
}
}
如何设置这些自定义属性?
【问题讨论】:
标签: javascript typescript azure azure-functions azureservicebus