[英]Azure Function not getting messages from Storage Queue
I have created test Azure function with queue trigger. 我已经使用队列触发器创建了测试Azure函数。 When I run this function in local emulator it works.
当我在本地仿真器中运行此功能时,它将起作用。 But when I deploy it on Azure, it looks like it's not working (messages are not being deleted from queue).
但是,当我在Azure上部署它时,它似乎无法正常工作(消息未从队列中删除)。
Function 功能
[FunctionName("Function1")]
public static void Run([QueueTrigger("azurefunc", Connection = "StorageConnectionString")]string myQueueItem, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
// PERFORMANCE TEST
for (int i = 0; i < 10000; i++)
{
for (int j = 0; j < 9000; j++)
{
// Do nothing.
// Or do something
string myAwesomeTempString = "How are you";
myAwesomeTempString += "?";
}
}
try
{
var queueMessage = new CloudQueueMessage (myQueueItem);
QueueApi.DeleteMessage (QueueApi.AzureFunctionStorageQueue, queueMessage);
}
catch
{
}
}
local.settings.json local.settings.json
{"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "AZURE_STORAGE_CONNECTION_STRING",
"AzureWebJobsDashboard": "AZURE_STORAGE_CONNECTION_STRING",
"StorageConnectionString": "AZURE_STORAGE_CONNECTION_STRING",
"serviceBusAccount": "SERVICE_BUS_CONNECTION_STRING"
}}
Part of QueueApi QueueApi的一部分
/// <summary>
/// Creates instance of Queue Storage
/// </summary>
/// <param name="queueName">Name of queue storage</param>
/// <returns>The instance of queue storage</returns>
private static CloudQueue CreateStorageQueue (string queueName)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse ("AZURE_STORAGE_CONNECTION_STRING");
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient ();
CloudQueue queue = queueClient.GetQueueReference (queueName);
queue.CreateIfNotExists ();
return queue;
}
/// <summary>
/// Deletes message from queue.
/// </summary>
/// <param name="queue">The queue storage instance</param>
/// <param name="message">Message to be deleted</param>
public static void DeleteMessage (CloudQueue queue, CloudQueueMessage message)
{
CheckInstances ();
if (message != null)
{
queue.DeleteMessage (message);
}
}
I created Azure Service Bus account just to test another approach, but I would really rather use Azure Storage Queue . 我创建了Azure Service Bus帐户只是为了测试另一种方法,但是我确实更愿意使用Azure Storage Queue 。
Can anyone please help me? 谁能帮帮我吗?
Thank you very much 非常感谢你
Queue Trigger will delete the incoming message automatically at the end of function execution, hence you don't need to delete it on your own. 队列触发器将在函数执行结束时自动删除传入的消息,因此您不需要自己删除它。 Your code actually creates a new message which has same message content as the one comes into function, and tries to delete the new message which doesn't exist in the queue.
您的代码实际上创建了一条新消息,该消息具有与该消息起作用的消息相同的消息内容,并尝试删除队列中不存在的新消息。
The reason the code doesn't work on Azure is that you may have forgotten to add StorageConnectionString
in Application settings. 该代码在Azure上不起作用的原因是您可能忘记了在应用程序设置中添加
StorageConnectionString
。 local.settings.json
is not published to Azure as it's only for local development. local.settings.json
仅用于本地开发,因此不会发布到Azure。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.