问题
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