0
votes

I am trying delete message by lock token with CompleteAsync method, but this does not always work. Сan i delete message from topic Azure Service Bus by message identifier?

1
You could try Delete Message. - Joy Wang
@JoyWang one would still need lock token. - Gaurav Mantri

1 Answers

0
votes

I think you are using Microsoft.Azure.ServiceBus library to perform messaging operations. By using this library, You can not delete the message by message Identifier. To delete the message need to pass the LockToken every time you perform Complete operation and there is no option to get the message using identifier.

If you want to do, then you should get messages first then iterate each one until you are getting the message you are searching for.

I would suggest, Windows.Azure.ServiceBus library, here you can delete the message without passing any tokens. Also, have an option to receive the message by using message sequence number. But WindowsAzure.ServiceBus doesn’t support .Net Core applications but Microsoft.Azure.ServiceBus would support.

 MessagingFactory factory = MessagingFactory.CreateFromConnectionString(connectionString);

            queueClient = await factory.CreateMessageReceiverAsync(_entityPath, ReceiveMode.PeekLock);

           BrokeredMessage _message = await queueClient.ReceiveAsync(sequenceNumber);
           await _message.CompleteAsync();