gpt4 book ai didi

windows - Azure:如何将消息从有害队列移回主队列?

转载 作者:行者123 更新时间:2023-12-04 00:58:14 25 4
gpt4 key购买 nike

我想知道是否有一个工具或库可以在队列之间移动消息?目前,我正在做类似下面的事情

public static void ProcessQueueMessage([QueueTrigger("myqueue-poison")] string message, TextWriter log)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connString);
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference("myqueue");
queue.CreateIfNotExists();

var messageData = JsonConvert.SerializeObject(data, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
queue.AddMessage(new CloudQueueMessage(messageData));
}

最佳答案

截至 (2018-09-11) Microsoft Azure Storage Explorer 版本 1.4.1无法将消息从一个 Azure 队列移动到另一个队列。

blogged一个简单的解决方案,用于将有害消息传输回原始队列,并认为这可能会节省某人几分钟的时间。显然,您需要修复导致消息最终出现在有害消息队列中的错误!

您需要将 NuGet 包引用添加到 Microsoft.NET.Sdk.Functions :

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;

void Main()
{
const string queuename = "MyQueueName";

string storageAccountString = "xxxxxx";

RetryPoisonMesssages(storageAccountString, queuename);
}

private static int RetryPoisonMesssages(string storageAccountString, string queuename)
{
CloudQueue targetqueue = GetCloudQueueRef(storageAccountString, queuename);
CloudQueue poisonqueue = GetCloudQueueRef(storageAccountString, queuename + "-poison");

int count = 0;
while (true)
{
var msg = poisonqueue.GetMessage();
if (msg == null)
break;

poisonqueue.DeleteMessage(msg);
targetqueue.AddMessage(msg);
count++;
}

return count;
}

private static CloudQueue GetCloudQueueRef(string storageAccountString, string queuename)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageAccountString);
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
CloudQueue queue = queueClient.GetQueueReference(queuename);

return queue;
}

关于windows - Azure:如何将消息从有害队列移回主队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33252196/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com