ServiceBusTrigger进程Deadletter消息

时间:2018-01-23 12:52:50

标签: azure servicebus

我有一个当前的主题队列,它将一些消息发送到deadletter queue。我正在创建另一个Webjob,它在deadletter队列上监听ServiceBusTrigger。目的是将deadletter mesg重新提交到要重新处理的原始队列

当新邮件进入deadletter队列时,我会克隆邮件并将其发送回原始主题订阅以重新处理。

我希望克隆消息将被发送到原始队列并保持在那里直到它被处理,但是当[originalTopicClient.Send(cloneMessage);]函数被调用时,结果消息就完成了。

我错过了什么吗?

public void ProcessQueueMessage([ServiceBusTrigger(topicName, dlqSubscription)] string message, TextWriter log)
   {
        MessagingFactory factory = MessagingFactory.Create(ServiceURI, tokenProvider);

            string deadLetterQueuePath = SubscriptionClient.FormatDeadLetterPath(topicName, SubscriptionName);

            SubscriptionClient dlqSubscriptionClient = factory.CreateSubscriptionClient(topicName, "mytopicsubscription/$DeadLetterQueue");
            QueueClient deadletterQueueClient = factory.CreateQueueClient(deadLetterQueuePath);
            BrokeredMessage cloneMessage;
            Microsoft.ServiceBus.Messaging.TopicClient originalTopicClient = Microsoft.ServiceBus.Messaging.TopicClient.CreateFromConnectionString(serviceBusEndpoint, topicName);

            BrokeredMessage dlqMessage;
            if ((dlqMessage = dlqSubscriptionClient.Receive()) != null)
            {
                cloneMessage = dlqMessage.Clone();
                cloneMessage.Properties.Remove("DeadLetterReason");
                cloneMessage.Properties.Remove("DeadLetterErrorDescription");

                originalTopicClient.Send(cloneMessage); //resend the clone message to original queue


                dlqMessage.Complete(); //deadletter queue mesg completed
            }
    }

0 个答案:

没有答案