简体   繁体   English

Azure功能 - c# - 带有Blob绑定的ServicebusTrigger

[英]Azure Function - c# - ServicebusTrigger with Blob binding

I have a python function with a servicebus trigger and a blob input binding. 我有一个带有servicebus触发器和blob输入绑定的python函数。 The name of the blob match the content of the queue message. blob的名称与队列消息的内容匹配。 My function.json file looks like that: 我的function.json文件看起来像这样:

{
"bindings": [
    {
    "type": "serviceBusTrigger",
    "name": "inputMessage",
    "connection": "Omnibus_Validation_Listen_Servicebus",
    "queueName": "validation-input-queue",
    "accessRights": "listen",
    "direction": "in"
    },
    {
    "type": "blob",
    "name": "inputBlob",
    "path": "baselines/{inputMessage}",
    "connection": "Omnibus_Blob_Storage",
    "direction": "in"
    }
],
"disabled": false
}

And it is working like a charm. 它的工作就像一个魅力。

I'd to create a C# function with the same bindings but it does not seem to work. 我将使用相同的绑定创建一个C#函数,但它似乎不起作用。 I've used the same function.json file. 我使用了相同的function.json文件。

I have a project.json file: 我有一个project.json文件:

{
    "frameworks": {
        "net46": {
            "dependencies": {
                "WindowsAzure.Storage": "8.5.0"
            }
        }
    }
}

and my run.csx file looks like that: 我的run.csx文件看起来像这样:

public static void Run(string inputMessage, Stream inputBlob, TraceWriter log)
{
    log.Info($"C# ServiceBus queue trigger function processed message: {inputMessage}");
}

When I save/run the function, I received this error: 保存/运行该功能时,收到此错误:

Function ($import-baseline) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.import-baseline'. 函数($ import-baseline)错误:Microsoft.Azure.WebJobs.Host:错误索引方法'Functions.import-baseline'。 Microsoft.Azure.WebJobs.Host: No binding parameter exists for 'inputMessage'. Microsoft.Azure.WebJobs.Host:'inputMessage'不存在绑定参数。

Is there any difference between the python and c# sdk for this kind of binding ? 对于这种绑定,python和c#sdk之间有什么区别吗?

I also can reproduce it on my side if I bind input blob path with baselines\\{serviceBusTrigger} or baselines\\{inputMessage} in the function.json file. 如果我在function.json文件baselines\\{inputMessage}输入blob路径与baselines\\{serviceBusTrigger}baselines\\{inputMessage}绑定在一起,我也可以在我身边重现它。

I am not sure whether it is supported to integrated input servicebus queue and input blob currently. 我不确定当前是否支持集成输入servicebus队列和输入blob。 We could give our feedback to Azure function team. 我们可以向Azure功能团队提供反馈

If Azure storage queue is acceptable we could use Azure storage queue trigger to do that. 如果Azure 存储队列是可接受的,我们可以使用Azure存储队列触发器来执行此操作。 I test it on my side, it works correctly. 我测试它在我身边,它正常工作。

在此输入图像描述

run.csx file run.csx文件

using System;
using System.Threading.Tasks;

public static void Run(string myQueueItem, Stream inputBlob, TraceWriter log)
{
    log.Info($"C# storage queue trigger function processed message: {myQueueItem}");
    StreamReader reader = new StreamReader(inputBlob);
    string text = reader.ReadToEnd();
    log.Info(text);
}

function.json function.json

{
  "bindings": [
    {
      "type": "blob",
      "name": "inputBlob",
      "path": "incontainer/{queueTrigger}",
      "connection": "testweblog_STORAGE",
      "direction": "in"
    },
    {
      "type": "queueTrigger",
      "name": "myQueueItem",
      "queueName": "myqueue",
      "connection": "testweblog_STORAGE",
      "direction": "in"
    }
  ],
  "disabled": false
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM