[英]Azure Function : async method and output parameters
I want to use output queue in my azure function. 我想在我的azure函数中使用输出队列。 I get an example code from: https://docs.microsoft.com/en-us/sandbox/functions-recipes/queue-storage
我从以下网址获取示例代码: https : //docs.microsoft.com/en-us/sandbox/functions-recipes/queue-storage
[FunctionName("BasicQueueOutput")]
public static void Run([TimerTrigger("*/30 * * * * *")]TimerInfo myTimer,
TraceWriter log,
[Queue("101functionsqueue",Connection = "AzureWebJobsStorage")] out string queueMessage)
{
log.Info("101 Azure Function Demo - Storage Queue output");
queueMessage = DateTime.UtcNow.ToString();
}
it works fine for sync method, but in my case it's async method: 它适用于同步方法,但在我的情况下,它是异步方法:
[FunctionName("FunctionRegisterDomain")]
public async static Task Run(
[QueueTrigger("domain-registation", Connection = "StorageConnectionString")]DomainForRegistration queueItem,
[Queue("domain-add-to-office365", Connection = "StorageConnectionString")]out DomainForRegistration outputQueue,
ILogger log)
and I get an error: 我收到一个错误:
Async methods cannot have ref, in or out parameters
异步方法不能有ref,in或out参数
of course, I can do it : 当然,我可以这样做:
[Queue("domain-add-to-office365", Connection = "StorageConnectionString")]CloudQueue outputQueue,
and then use it: 然后使用它:
await outputQueue.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(queueItem)));
but I would like to do it with bindings to queue message 但我想用绑定队列消息来做到这一点
You are looking for IAsyncCollector<T>
to change from out param to that. 您正在寻找
IAsyncCollector<T>
从out param更改为。 Instead of “out string message” you change to ICollector<string> messages
or IAsyncCollector<string>
and add you message to the collection in the body. 您可以更改为
ICollector<string> messages
或IAsyncCollector<string>
,而不是“输出字符串消息”,并将消息添加到正文中的集合中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.