通过HTTP端点触发时

通过HTTP端点触发时

本文介绍了通过HTTP端点触发时,带有enqueueTimeUtc参数的ServiceBusTrigger失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2017在本地的Azure Functions v1中开发服务总线触发器.我想测试 example 来自官方文档,而无需在服务总线中添加消息.因此,我通过邮递员在端点POST上触发了它 http://localhost:7071/admin/functions/ServiceBusQueueTriggerCSharp 正文为 {"input":"foo"} .

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

此操作失败,并出现脚本宿主错误:执行功能:ServiceBusQueueTriggerCSharp时发生异常.Microsoft.Azure.WebJobs.Host:发生一个或多个错误.异常绑定参数"deliveryCount".Microsoft.Azure.WebJobs.Host:绑定数据不包含期望值'deliveryCount'.

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'.

我尝试删除 deliveryCount 参数,但随后在 enqueueTimeUtc 处失败.删除它也可以.有没有办法保留这些参数并在本地测试Function?

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?

我知道这两个参数在通过HTTP触发时没有多大意义,但是可以给它们提供默认值. messageId 的值非零.

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.

示例供参考:

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

推荐答案

到目前为止,如果您希望能够使用这些其他元数据属性,则需要使用真实的服务总线消息.

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.

理论上,管理端点可以足够聪明,以允许您传递其他绑定数据(在本例中为deliveryCount)作为查询参数.我提出了以下功能请求以进行跟踪: https://github.com/Azure/azure-functions-host/issues/2955

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

这篇关于通过HTTP端点触发时,带有enqueueTimeUtc参数的ServiceBusTrigger失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 00:18