Poison Queue content into main queue

狂风中的少年 提交于 2021-02-11 12:26:19

问题


I am trying to move poison messages into the main queue. I am not facing any problem in moving the messages, but looks like message is getting converted to some other encryption level.

<bound method DictMixin.values of {'id': '389a834e-48af-41b5-be36-5f61ad7c2232', 'inserted_on': 
datetime.datetime(2020, 6, 30, 3, 13, tzinfo=datetime.timezone.utc), 
'expires_on': datetime.datetime(2020, 7, 7, 3, 13, tzinfo=datetime.timezone.utc),
'dequeue_count': 0, 'content': 
'eyJjYWxsX2JhY2tfdXJpIjogImh0dHBzOi8vcG9zdG1hbi1lY2hvLmNvbS9wb3N0IiwgInBpcGVsaW5lX3J1bl
 9pZCI6ICI3OTY1MGU3Zi01NmFmLTRiYzgtOWE3NC0yYTk3YWRhOWRhNWUiLCAiZXhlY
 3V0aW9uX2lkIjogImRmYzcwMjAwLTY3MzgtNDNkMy1',
 'pop_receipt': None, 'next_visible_on': None}>

how can I convert content into the message queue ?


回答1:


As version 1.4.1 of the Microsoft Azure Storage Explorer doesn’t have the ability to move messages from one Azure queue to another.

Here is a simple solution to transfer poison messages back to the originating queue. Obviously, you'll need to have fixed the error that caused the messages to end up in the poison message queue!

You’ll need to add a NuGet package reference to 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;
}


来源:https://stackoverflow.com/questions/62649998/poison-queue-content-into-main-queue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!