小编Kim*_*men的帖子

Azure IoT Hub,EventHub和Functions

我有一个IoTHub,其路由指向触发函数的EventHub.

我在从事件对象获取DeviceId和其他IoT Hub属性时遇到问题,而没有将这些属性显式添加到有效负载.

如果我将输入类型设置为string(或自定义类型):

public static void Run(string iotMessage, TraceWriter log) {
    log.Info($"C# Event Hub trigger function processed a message: {iotMessage}");
}
Run Code Online (Sandbox Code Playgroud)

我只获得有效负载而没有任何其他IoT Hub属性,如DeviceId,CorrelationIdMessageId.

我尝试将类型设置为EventData:

public static void Run(EventData iotMessage, TraceWriter log) {
    log.Info($"C# Event Hub trigger function processed a message: {JsonConvert.SerializeObject(iotMessage)}");
}
Run Code Online (Sandbox Code Playgroud)

现在我可以通过两个getter访问IoT Hub属性:Properties和SystemProperties.例如,我可以像这样访问DeviceId iotMessage.SystemProperties["iothub-connection-device-id"].但它不会暴露有效载荷.

那么如何访问IoT Hub属性和有效负载?

azure azure-eventhub azure-iot-hub azure-functions

7
推荐指数
1
解决办法
2110
查看次数

为什么某些 Azure CLI 命令需要 az login

在我们的 VSTS 发布管道中,我们想要调用一个 powershell 脚本,该脚本为我的 Azure 函数之一添加函数密钥(使用密钥管理 rest API)。

我根据这篇文章创建了一个脚本:https : //www.markheath.net/post/managing-azure-function-keys

Param(
    [string] [Parameter(Mandatory=$true)] $ResourceGroup,
    [string] [Parameter(Mandatory=$true)] $AppName,
    [string] [Parameter(Mandatory=$true)] $FunctionName,
    [string] [Parameter(Mandatory=$true)] $KeyName,
    [string] [Parameter(Mandatory=$true)] $KeyValue
    )

    function getAuthenticationToken([string]$appName, [string]$resourceGroup)
    {
    $user = az webapp deployment list-publishing-profiles -n $appName -g $resourceGroup `
            --query "[?publishMethod=='MSDeploy'].userName" -o tsv

    $pass = az webapp deployment list-publishing-profiles -n $appName -g $resourceGroup `
            --query "[?publishMethod=='MSDeploy'].userPWD" -o tsv

    $pair = "$($user):$($pass)"
    $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))

    $jwt = Invoke-RestMethod -Uri "https://$appName.scm.azurewebsites.net/api/functions/admin/token" -Headers @{Authorization=("Basic {0}" -f $encodedCreds)} …
Run Code Online (Sandbox Code Playgroud)

powershell azure azure-cli azure-devops azure-pipelines

5
推荐指数
1
解决办法
1181
查看次数

Azure功能使用Binder更新DocumentDb文档

之前关于Azure Functions的帖子的后续问题.我需要使用命令式绑定器(Binder)更新DocumentDB中的文档.我真的不明白文档,我找不到任何例子(我或多或少找到一种TextWriter的例子).文档说我可以绑定到"out T",我找不到这个例子.

在运行函数之前说文档看起来像这样:

{
    child: {
        value: 0
    }
}
Run Code Online (Sandbox Code Playgroud)

功能看起来像这样:

var document = await binder.BindAsync<dynamic>(new DocumentDBAttribute("myDB", "myCollection")
{
    ConnectionStringSetting = "my_DOCUMENTDB",
    Id = deviceId
});

log.Info($"C# Event Hub trigger function processed a message: document: { document }");

document.value = 100;
document.child.value = 200;

log.Info($"Updated document: { document }");
Run Code Online (Sandbox Code Playgroud)

根据第二个日志记录行,文档未正确更新.子项未更新(从商店读取时存在)并添加了值.无论哪种方式,都没有任何东西存在.我已经尝试在function.json中添加一个输出,但是编译器抱怨它并且文档声明你不应该有任何输出.

我错过了什么?

azure azure-functions azure-cosmosdb

3
推荐指数
1
解决办法
1480
查看次数