ServiceBusTrigger with enqueueTimeUtc argument fails when triggered via HTTP endpoint

▼魔方 西西 提交于 2021-02-09 08:16:56

问题


I'm developing a Service Bus Trigger in Azure Functions v1 locally with Visual Studio 2017. I want to test the example from the official docs without having to put a message in the service bus. So I trigger it via Postman at endpoint POST http://localhost:7071/admin/functions/ServiceBusQueueTriggerCSharp with body { "input": "foo" }.

This fails with a script host error: Exception while executing function: ServiceBusQueueTriggerCSharp. Microsoft.Azure.WebJobs.Host: One or more errors occurred. Exception binding parameter 'deliveryCount'. Microsoft.Azure.WebJobs.Host: Binding data does not contain expected value 'deliveryCount'.

I tried removing the deliveryCount argument, but then it fails at enqueueTimeUtc. Removing that too works. Is there a way to keep these arguments and test the Function locally?

I understand that these two arguments wouldn't make much sense when triggered via HTTP, but they could be given default values. messageId has a non-zero value.

Example for reference:

[FunctionName("ServiceBusQueueTriggerCSharp")]                    
public static void Run(
    [ServiceBusTrigger("myqueue", AccessRights.Manage, Connection = "ServiceBusConnection")] 
    string myQueueItem,
    Int32 deliveryCount,       // this fails
    DateTime enqueuedTimeUtc,  // this fails too
    string messageId,
    TraceWriter log)
{
    log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}");
    log.Info($"EnqueuedTimeUtc={enqueuedTimeUtc}");
    log.Info($"DeliveryCount={deliveryCount}");
    log.Info($"MessageId={messageId}");
}

回答1:


As of right now, if you want to be able to work with these additional metadata properties, you'll need to use a real service bus message.

In theory, the admin endpoint could be smart enough to allow you to pass additional binding data (such as deliveryCount in this case) as query parameters. I filed the following feature request to track: https://github.com/Azure/azure-functions-host/issues/2955



来源:https://stackoverflow.com/questions/50725773/servicebustrigger-with-enqueuetimeutc-argument-fails-when-triggered-via-http-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!