【问题标题】:Azure Function - c# - ServicebusTrigger with Blob bindingAzure Function - c# - ServicebusTrigger 与 Blob 绑定
【发布时间】:2018-03-23 22:13:15
【问题描述】:

我有一个带有服务总线触发器和 blob 输入绑定的 python 函数。 Blob 的名称与队列消息的内容相匹配。 我的 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
}

而且它的作用就像一个魅力。

我想创建一个具有相同绑定的 C# 函数,但它似乎不起作用。 我使用了相同的function.json 文件。

我有一个project.json 文件:

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

我的run.csx 文件看起来像这样:

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

当我保存/运行函数时,我收到了这个错误:

函数 ($import-baseline) 错误:Microsoft.Azure.WebJobs.Host:错误索引方法“Functions.import-baseline”。 Microsoft.Azure.WebJobs.Host:“inputMessage”不存在绑定参数。

这种绑定python和c#sdk有区别吗?

【问题讨论】:

  • 看起来不错。尝试删除 project.json,在这种情况下不需要它。
  • @Mikhail,不工作:-(
  • 是的...问题出在baselines/{inputMessage} 语法上。但有趣的是它可以在 python 中工作......
  • 是的,我知道 queueTrigger 的语法不同,我试过 baselines/{inputMessage} 并且它工作正常。我也试过baselines/{serviceBusTrigger},但没有运气
  • @Thomas 我有一个问题,但与您的问题不同。我只是想知道当您将消息发送到队列时如何传递 {inputMessage} 命名参数。你在哪里有 Python 示例吗?我知道这个 {inputMessage} 应该是队列消息中的命名参数。我使用 Python SDK 插入消息,但找不到任何方法来传递命名参数。

标签: c# python azure-blob-storage azure-functions azure-servicebus-queues


【解决方案1】:

如果我在 function.json 文件中将输入 blob 路径与 baselines\{serviceBusTrigger}baselines\{inputMessage} 绑定,我也可以在我这边重现它。

我不确定目前是否支持集成输入服务总线队列和输入 blob。我们可以将 feedback 提供给 Azure 功能团队。

如果 Azure 存储队列 是可接受的,我们可以使用 Azure 存储队列触发器来执行此操作。我自己测试了一下,它工作正常。

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

{
  "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
}

【讨论】:

  • 谢谢汤姆,我知道它正在使用 queueTrigger。想知道为什么它使用 Python 而不是 C# :-)
  • Was wondering why it is working with Python and not with C# 我假设它目前没有在 C# 中实现,因为它们是不同的库。
  • 您无法使用服务总线队列进行输入绑定
猜你喜欢
  • 2020-08-27
  • 1970-01-01
  • 1970-01-01
  • 2019-11-06
  • 2019-10-22
  • 1970-01-01
  • 2021-08-02
  • 1970-01-01
  • 2021-09-04
相关资源
最近更新 更多