Azure Service Bus Queue Message strikethrough after Message.Abandon

I am testing the Azure Service Bus queue. I have the code below:

Queue dispatch:

string strConnectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
        var namespaceManager = NamespaceManager.CreateFromConnectionString(strConnectionString);
        if (!namespaceManager.QueueExists("Test"))
        {
            QueueDescription qD = new QueueDescription("Test");
            qD.DefaultMessageTimeToLive = new TimeSpan(05, 00, 00);
            qD.LockDuration = new TimeSpan(00, 02, 30);
            qD.MaxSizeInMegabytes = 5120;                
            namespaceManager.CreateQueue(qD);              
        }
        if (namespaceManager.QueueExists("Test"))
        {
            QueueClient client = QueueClient.CreateFromConnectionString(strConnectionString, "Test", ReceiveMode.PeekLock);
            var qMessage = Console.ReadLine();
            using (MemoryStream strm = new MemoryStream(Encoding.UTF8.GetBytes(qMessage)))
            {
                BrokeredMessage bMsg = new BrokeredMessage(strm);
                bMsg.MessageId = Guid.NewGuid().ToString();
                bMsg.TimeToLive = new TimeSpan(05, 00, 00);
                client.Send(bMsg);
                Console.WriteLine("Message sent");
            }
        }
        Console.ReadLine();

Receipt Code:

 string strConnectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
        var namespaceManager = NamespaceManager.CreateFromConnectionString(strConnectionString);
        if (namespaceManager.QueueExists("Test"))
        {
            QueueClient client = QueueClient.CreateFromConnectionString(strConnectionString, "Test",ReceiveMode.PeekLock);
            if (client != null)
            {
                OnMessageOptions options = new OnMessageOptions();
                options.AutoComplete = false;
                options.AutoRenewTimeout = TimeSpan.FromSeconds(31);                 


                client.OnMessage((message) =>
                    {                           
                        Console.WriteLine(message.State.ToString());
                        Console.WriteLine("Message Id: " + message.MessageId);
                        Stream stream = message.GetBody<Stream>();
                        StreamReader reader = new StreamReader(stream);
                        Console.WriteLine("Message: " + reader.ReadToEnd());                                
                        Console.WriteLine("***************");
                        message.Abandon();
                    });
                Console.ReadLine();
            }
        }

I see that whenever I call Abandon , the message gets DeadLettered. My assumption was that he should be active and could be chosen by another client.

+4
source share
1 answer

BrokeredMessage.Abandon Api . , ( ) , , .

, :

"" . (Job-Queue), - ReceiveMode.PeekLock. ( ) (Job) . , brokeredMessage 4 , .

"" :

! Sree

+15

Source: https://habr.com/ru/post/1620447/


All Articles