【问题标题】:Azure Functions Output to EventHubAzure Functions 输出到 EventHub
【发布时间】:2022-08-23 13:44:39
【问题描述】:

我有一个用 NodeJS 构建的 Azure 函数,它在 HTTP 触发器上接收数据,处理数据,然后必须将处理后的数据输出到 Azure 事件中心,以便在 Azure ADX 中摄取。输出数据是 JSON 格式的有效负载。

流动:
AZ 函数(HTTP 触发器)-> AZ 事件中心-> AZ ADX

使用 EventHubProducerClient 类(来自 NPM @azure/event-hubs),我能够将数据发布到事件中心,然后将其链接到 ADX 并摄取数据。 (如果您构建应用服务,这通常是遵循的方法)。

我想利用烘烤的Azure 函数绑定对于 eventHub(使用 Microsoft.Azure.Functions.ExtensionBundle),我已经设置了设置:

{
  \"bindings\": [
    {
      \"authLevel\": \"function\",
      \"type\": \"httpTrigger\",
      \"direction\": \"in\",
      \"name\": \"req\",
      \"methods\": [\"post\"],
      \"route\": \"upload\"
    },
    {
      \"type\": \"http\",
      \"direction\": \"out\",
      \"name\": \"res\"
    },    
    {
      \"type\": \"eventHub\",
      \"name\": \"outputEventHub\",
      \"eventHubName\": \"%AZEH_EVENTHUB_NAME%\",
      \"connection\": \"AZEH_CONNECTION_STRING\",
      \"direction\": \"out\"
    }
}

参考:https://github.com/uglide/azure-content/blob/master/articles/azure-functions/functions-bindings-event-hubs.md#azure-event-hub-output-binding

我一直在尝试在绑定中找到有关 dataType 属性的文档(在 function.json 中设置),但我能找到的最好的文档是指定支持的类​​型的文档,但没有说明如何实现它。我看到的最好的是设置

\"dataType\": \"string\"

支持的类型列表:

  • Azure.Messaging.EventHubs.EventData
  • 字符串
  • 字节数组
  • 普通旧 CLR 对象 (POCO)

参考:https://github.com/MicrosoftDocs/azure-docs/blob/main/articles/azure-functions/functions-bindings-event-hubs-output.md

在我处理触发器的函数中,我将上下文绑定设置为 JSON 数据,例如:

context.bindings.outputEventHub = jsonData;

但数据无法通过 ADX。

有人对如何设置 AZ 函数以通过事件中心将数据摄取到 ADX 有一些参考吗?

    标签: azure azure-functions azure-eventhub


    【解决方案1】:

    我相信数据已从 azure 函数正确发送到事件中心。但是,当摄取发生在 azure data explorer 时,您将面临问题。当您配置从事件中心摄取数据到 azure 数据探索时,您能否确认您是否指定了数据格式。请参阅target table configuration 部分。如果您的事件中心的数据格式与您从 azure 函数发送的数据格式不同,那么您可以观察到问题。请确保您正在序列化数据。如果您要传递 JSON 对象,则可以利用 JsonConvert.SerializeObject(yourdata) 将 JSON 消息传递到事件中心。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-02
      • 1970-01-01
      • 1970-01-01
      • 2017-04-06
      相关资源
      最近更新 更多