我有一个Azure服务总线队列。当我将文件发送到此队列时,它将进入死信队列。当我尝试将消息(文件)从DLQ重新提交到其原始队列时,它再次返回到DLQ,但现在该文件的内容正在获取垃圾邮件。任何人都能帮助我吗?
重新提交的代码如下。
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;
}
}
答案 0 :(得分:1)
您使用BrokeredMessage(serializedObject)
的构造函数假定您传入的内容是要序列化的有效负载(消息正文),而不是克隆信息的消息。
ASB SDK专门用于BrokeredMessage.Clone()
。
注意:注意到您正在混合异步和同步呼叫。无论ASB如何,这都会让您陷入困境。可能希望切换到同步或使用await
进行适当的异步调用。