【问题标题】:How to add user properties to Service Bus topic output from Javascript Azure Function如何将用户属性添加到 Javascript Azure 函数的服务总线主题输出
【发布时间】: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


    【解决方案1】:

    到今天为止,没有办法使用非 C# 语言中的绑定来设置元数据。解决方法是直接使用服务总线 SDK 发送消息。

    this feature request,您可以投票以获得更多关注。

    【讨论】:

      猜你喜欢
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 2019-03-24
      • 1970-01-01
      相关资源
      最近更新 更多