2

我有一个带有servicebus触发器和blob输入绑定的python函数。 blob的名称与队列消息的内容相匹配。 我function.json文件看起来像这样:Azure函数 - c# - 带Blob绑定的ServicebusTrigger

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

当我保存/运行功能,我收到此错误:

Function ($import-baseline) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.import-baseline'. Microsoft.Azure.WebJobs.Host: No binding parameter exists for 'inputMessage'.

这种python和c#sdk之间有什么区别吗?绑定?

+0

看起来不错。尝试删除project.json,在这种情况下不需要。 – Mikhail

+0

@Mikhail,不工作:-( – Thomas

+0

是的......问题出在'baselines/{inputMessage}'的语法,但有趣的是它在python中有效...... – Mikhail

回答

0

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

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

如果Azure 存储队列是可以接受的,我们可以使用Azure存储队列触发器来做到这一点。我在我身边测试它,它工作正常。

enter image description here

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 
} 
+0

谢谢Tom,我知道它正在处理queueTrigger,想知道为什么它使用Python而不是C# :-) – Thomas

+0

'想知道为什么它使用Python而不是使用C#'我假设它目前没有在C#中实现,因为它们是不同的库。 –