[英]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.