Quantcast
Channel: Service Bus forum
Viewing all articles
Browse latest Browse all 1916

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

$
0
0

I'm able to send message to Main from Deadletter using below code but issue is unable to complete that message.

error at this line - await deadletterReceiver.CompleteAsync(newMessage.SystemProperties.LockToken);

System.InvalidOperationException: Operation is not valid due to the current state of the object. at Microsoft.Azure.ServiceBus.Message.SystemPropertiesCollection.ThrowIfNotReceived() at Microsoft.Azure.ServiceBus.Message.SystemPropertiesCollection.get_LockToken()

publicstatic async System.Threading.Tasks.TaskRunAsync([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 =newMessageReceiver(Environment.GetEnvironmentVariable("ConnectionStringSettingName"), deadQueuePath,ReceiveMode.PeekLock,RetryPolicy.Default);MessageSender sender =newMessageSender(Environment.GetEnvironmentVariable("ConnectionStringSettingName"),"demo",RetryPolicy.Default);var deadLetter = await deadletterReceiver.ReceiveAsync();if(deadLetter !=null){
                            log.LogInformation($"got new message");Message newMessage =newMessage(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}");}}


Viewing all articles
Browse latest Browse all 1916

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>