0
votes

I am trying to schedule messages in azure service bus and few messages are getting stuck in scheduled queue and never returned to active queue even after reaching ScheduledEnqueueTimeUtc

The code for sending scheduled BrokeredMessage is very normal:

var message = new BrokeredMessage(info);
message.Properties.Add("Action", "Bookmark");
message.ContentType = "Info";
message.ScheduledEnqueueTimeUtc = DateTime.UtcNow.AddMinutes(Int32.Parse(ConfigurationManager.AppSettings["Delay"]));
var serviceBusClient = QueueClient.CreateFromConnectionString(ConfigurationManager.AppSettings["ConnectionString"], ConfigurationManager.AppSettings["ServiceBusQueueName"]);
serviceBusClient.Send(message);

Out of 20,000 messages I sent while testing only 6 messages were stuck and also at random times.

Below is the screenshot in debug mode Screenshot for invalid ExpiresAtUtc

Notes: Initially I thought messages were stuck because of bad ExpiresAtUtc but after some reading found that when a new messages is scheduled its ExpiresAtUtc is 12/31/9999 11:59:59 PM Also I found that when a messages is scheduled by cloning a message from Queue then ExpiresAtUtc for the scheduled message will not be 12/31/9999 11:59:59 PM but will be its proper ExpiresAtUtc time even when it is in scheduled queue

1
That's not a problem. ExpiresAtUtc is assigned to year 9999 by defaultMikhail Shilkov
Firstly, as Mikhail said, the ExpiresAtUtc of a scheduled BrokeredMessage is assigned to year 9999 by default. Secondly, in this article we can find: Message enquing time does not mean that the message will be sent at the same time.It will get enqueued, but the actual sending time depends on the queue's workload and its state.do those 6 scheduled messages not still get enqueued until today?Fei Han
Yes @FredHan even today they are stuck, if you see the EnqueuedTimeUtc, its 9/11, so its stuck in scheduled queue for last 3days and there is no workload on that queueuser844105
Messages would not normally just get stuck. Either they were deferred or there's something wrong with the queue. Can you pick this messages and verify they are not deferred?Sean Feldman
Hi @SeanFeldman they are not deferred messages, as you see in the screenshot, the state is "Scheduled" Out of 20,000 messages that i processed that day in same manner, only 6 messages faileduser844105

1 Answers

0
votes

As we mentioned, the ExpiresAtUtcof a scheduled message is assigned to year 9999 by default, which should not be the cause of the issue.

According to your screenshot, those messages do not become active (state of message is “Scheduled”), you can try to call CancelScheduledMessageAsync() method and check if the message can be canceled.

client.CancelScheduledMessageAsync(sequenceNumber)

Besides, you can try to create a new Azure Service Bus queue and run your code to send scheduled messages to that new queue, and check if same issue can appears in the new queue. If the issue only appears in that specific queue, you can create a support request and get help from Azure support engineer.