public void DequeueMessage(string queueName)
{
// Get the connection string from app settings
string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"];
// Instantiate a QueueClient which will be used to manipulate the queue
QueueClient queueClient = new QueueClient(connectionString, queueName);
if (queueClient.Exists())
{
// Get the next message
QueueMessage[] retrievedMessage = queueClient.ReceiveMessages();
// Process (i.e. print) the message in less than 30 seconds
Console.WriteLine($"Dequeued message: '{retrievedMessage[0].Body}'");
// Delete the message
queueClient.DeleteMessage(retrievedMessage[0].MessageId, retrievedMessage[0].PopReceipt);
}
}
2条答案
按热度按时间b1zrtrql1#
听起来你想要一个出队进程而不是一个触发进程。试试微软文档中演示的这个例子。
https://learn.microsoft.com/en-us/azure/storage/queues/storage-tutorial-queues?tabs=dotnet%2Cenvironment-variable-windows#dequeue-messages
摘录如下
看起来你也可以调整最大批量大小。
t0ybt7op2#
我读你的问题,好像你需要一个timer triggered fuction,以采取消息(出队)的队列。
因此,您需要创建一个计时器触发函数,如下所示:
然后调用
dequeue
的函数,从docs获取队列中的消息