简体   繁体   中英

Azure Service Bus DeadLetter QUEUE

I have a Azure service bus queue. When I am sending a file to this queue it is going to its dead letter queue. When I try re-submitting the message (file) from DLQ to its original queue, It is again going back to DLQ but now the content of the file is getting SPAM. Can any one help me with this?

The code for re-submission is below.

string connectionString = ConfigurationManager.AppSettings["connectionString"];

string queueName = ConfigurationManager.AppSettings["deadLetterQueueName"];

ServiceBusConnectionStringBuilder builder = new  ServiceBusConnectionStringBuilder(connectionString);

MessagingFactory factory = MessagingFactory.CreateFromConnectionString(builder.ToString());

var client = QueueClient.CreateFromConnectionString(connectionString, queueName);

string queueDeadletterPath = QueueClient.FormatDeadLetterPath(queueName);

QueueClient deadletterQueueClient = factory.CreateQueueClient(queueDeadletterPath);


            while (true)
            {
                BrokeredMessage msg = deadletterQueueClient.Receive();
                if (msg != null)
                {
                    try
                    {
                        if(msg.Label == "Resubmitted")
                        {
                            msg.Complete();
                        }
                        else
                        {
                            BrokeredMessage sendMsgBackToQueue = new BrokeredMessage(msg);
                            foreach(var prop in msg.Properties)
                            {
                                var targetProp = new KeyValuePair<string, object>(prop.Key, prop.Value);
                                sendMsgBackToQueue.Properties.Add( targetProp);
                            }
                            sendMsgBackToQueue.Label = "Resubmitted";
                            Console.WriteLine("Message Resubmitted");
                            client.SendAsync(sendMsgBackToQueue);
                            msg.Complete();
                        }
                    }
                    catch (Exception ex)
                    {
                        // Log error
                        Console.WriteLine(ex.Message);
                        msg.Abandon();
                    }
                }
                else
                {
                    break;
                }
            }

Screenshot

The constructor you're using BrokeredMessage(serializedObject) assumes that what you pass in is the payload (body of the message) to serialize, not a message to clone information from.

ASB SDK has a dedicated BrokeredMessage.Clone() just for this purpose.

Note: noticed you're mixing async and synchronous calls. This is going to get you in trouble regardless of ASB. Might want to switch to either sync or have proper async calls invocation with await .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM