Azure 函数使用 Powershell 使用来自事件中心的数据并将其发布到 REST API [英] Azure function using Powershell to consume the data from an Event hub and POST the same to a REST API

查看:12
本文介绍了Azure 函数使用 Powershell 使用来自事件中心的数据并将其发布到 REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Powershell 创建一个 Azure 函数,该函数将从 Azure 事件中心读取数据.Azure 函数有一个模板可以从 Azure 事件中心获取数据,但我不知道如何将相同的数据发布到本地托管的 REST API.
我已经为本地连接创建了一个混合连接.
我是 Powershell 开发的新手,因此寻求您的帮助.此外,如果有人可以建议任何博客以获取有关使用 Powershell 的 azure 函数开发标准实践的更多详细信息,那将是一个很大的帮助.

I want to create a Azure function using Powershell which will read data from the Azure Event Hub. Azure function has a template to get the data from the Azure Event hub and but I don't know how to post the same data to a REST API hosted on on-prem.
I have already created a hybrid connection for the on-prem connectivity.
I am new to Powershell development hence seeking your help. Also, it would be a great help if someone can suggest any blog(s) to get more details on azure function development standard practice using Powershell.

以下是我要更新的代码片段.

Following is the code snippet that I want to update.

run.ps1

param($eventHubMessages, $TriggerMetadata)

Write-Host "PowerShell eventhub trigger function called for message array: $eventHubMessages"

$eventHubMessages | ForEach-Object { Write-Host "Processed message: $_" }

host.json

{
  "version": "2.0",
  "managedDependency": {
    "Enabled": true
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  }
}

function.json

{
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "eventHubMessages",
      "direction": "in",
      "eventHubName": "pwo-events",
      "connection": "eventhub-reciever-policy",
      "cardinality": "many",
      "consumerGroup": "$Default"
    }
  ]
}

推荐答案

要从powershell脚本中的代码访问对象,必须在脚本的param部分添加function.json文件中绑定的名称.

To access to the object from the code in powershell script, the name of the bindings in the function.json file must be added in param section of the script.

# Input bindings passed via param 

param([byte[]] $Trigger, [String[]] $InputBlob, $TriggerMetadata) 


# Output passed via Push-OutputBinding 

Push-OutputBinding -name OutputBlob -value $SomeValue 

流程结构:

此外,我们有一个博客,其中包含有关 eventthub 遥测的信息 Powershell.

Also, we have a blog which covers the info about eventhub telemetry with Powershell.

这篇关于Azure 函数使用 Powershell 使用来自事件中心的数据并将其发布到 REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆