简体   繁体   English

如何将消息从Deadletter主题发送到Main并使用.net core C#完成消息

[英]How to send message from Deadletter topic to Main and complete it using .net core c#

I'm able to send message to Main from Deadletter using below code but issue is unable to complete that message. 我可以使用以下代码从Deadletter向Main发送消息,但问题无法完成该消息。

error at this line - await deadletterReceiver.CompleteAsync(newMessage.SystemProperties.LockToken); 在此行发生错误- await deadletterReceiver.CompleteAsync(newMessage.SystemProperties.LockToken);

System.InvalidOperationException: Operation is not valid due to the current state of the object. System.InvalidOperationException:由于对象的当前状态,操作无效。 at Microsoft.Azure.ServiceBus.Message.SystemPropertiesCollection.ThrowIfNotReceived() at Microsoft.Azure.ServiceBus.Message.SystemPropertiesCollection.get_LockToken() 在Microsoft.Azure.ServiceBus.Message.SystemPropertiesCollection.ThrowIfNotReceived()处Microsoft.Azure.ServiceBus.Message.SystemPropertiesCollection.get_LockToken()

public static async System.Threading.Tasks.Task RunAsync([TimerTrigger("0 */2 * * * *")]TimerInfo myTimer, ILogger log)
{
    log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    try
    {

        var deadQueuePath = EntityNameHelper.FormatDeadLetterPath("demo/subscriptions/demo");

        MessageReceiver deadletterReceiver = new MessageReceiver(Environment.GetEnvironmentVariable("ConnectionStringSettingName"), deadQueuePath, ReceiveMode.PeekLock,RetryPolicy.Default);
        MessageSender sender = new MessageSender(Environment.GetEnvironmentVariable("ConnectionStringSettingName"), "demo",RetryPolicy.Default);

        var deadLetter = await deadletterReceiver.ReceiveAsync();
        if (deadLetter != null)
        {
            log.LogInformation($"got new message");

            Message newMessage = new Message(deadLetter.Body)
            {
                ContentType = deadLetter.ContentType,
                CorrelationId = deadLetter.CorrelationId                          
            };

            //Send the message to the Active Queue
            await sender.SendAsync(newMessage);
            await deadletterReceiver.CompleteAsync(newMessage.SystemProperties.LockToken); //Unlock the message and remove it from the DLQ
            log.LogInformation($"Unlock the message and remove it from the DLQ");
        }
    }
    catch (Exception ex)
    {
        log.LogInformation($"Exception: {ex}");
    }
}

Shouldn't you be using the lock token from the deadletter message? 您不应该使用Deadletter消息中的锁令牌吗?

Essentially change this line of code: 从本质上更改以下代码行:

 await deadletterReceiver.CompleteAsync(newMessage.SystemProperties.LockToken); //Unlock the message and remove it from the DLQ

to

 await deadletterReceiver.CompleteAsync(deadLetter.SystemProperties.LockToken); //Unlock the message and remove it from the DLQ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从服务总线主题死信队列C#中读取? - How to read from service bus topic deadletter queue c#? 如何从 .net 核心应用程序向服务总线主题发送消息 - How to send a message to service bus topic from .net core application 如何使用 C# dot.net 客户端以编程方式创建主题并向 Kafka 发送消息 - How to programatically create topic and send message to Kafka using C# dot net client 如何在Azure Service Bus主题上删除DeadLetter消息 - How do I delete a DeadLetter message on an Azure Service Bus Topic 如何使用C#.NET CORE 2.0将FIX登录消息发送到GDAX - How to send FIX logon message with C# .NET CORE 2.0 to GDAX 如何使用Kafka-net在C#中创建新主题 - How to create new topic in c# by using kafka-net C#Firebase Cloud Message使用主题消息发送多个Web JS通知 - C# Firebase Cloud Message send multiple Web JS notifications using Topic messaging 如果发生异常,是否有任何方法可以使用 c# 将消息发送到死信主题? - If exception occurs is there any way to send message into dead letter topic using c#? 如何使用 SendMessage (WM_COPYDATA) 将消息从 C# 发送到 C++ (MESSAGE ONLY WINDOW)? - How to send message from C# to C++ (MESSAGE ONLY WINDOW) using SendMessage (WM_COPYDATA)? 使用C#中的32feet.net库从Windows发送bMessage到消息访问服务器 - Send bMessage to Message Access Server from Windows using 32feet.net library in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM