我正在开发一个 TypeScript Azure Function,该函数将 Azure 服务总线主题作为其输出。我可以用它发送消息,没有任何问题,但我无法将任何元数据设置为消息的自定义属性。
我尝试使用与 ServiceBusMessage 具有相同接口(interface)的对象来自服务总线 Javascript SDK,如下所示:
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;
但是消息
按原样发送,并且不考虑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)"
}
}
如何设置这些自定义属性?
最佳答案
截至目前,无法使用非 C# 语言中的绑定(bind)来设置元数据。解决方法是直接使用服务总线 SDK 发送消息。
有this feature request您可以投票以获得更多关注。
关于javascript - 如何将用户属性添加到 Javascript Azure Function 的服务总线主题输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73292661/