可以使用标准队列服务队列作为中介,将两个触发器隔离开来,以确保http触发器API不受queue触发器作业处理的影响。以下是代码示例:
在第一个函数中处理httpTrigger:
[FunctionName("HttpFunction")]
public static async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "myroute")] HttpRequest req,
[ServiceBus("myqueue", Connection = "ServiceBusConnection")] IAsyncCollector queueCollector)
{
// process httpTrigger request here
// add a message to the Service Bus queue
await queueCollector.AddAsync("message");
return new OkObjectResult("HTTP request processed successfully!");
}
在第二个函数中处理queueTrigger:
[FunctionName("QueueFunction")]
public static async Task Run(
[QueueTrigger("myqueue", Connection = "ServiceBusConnection")] string message)
{
// process message received from the queue
}