Azure service bus messages stuck in scheduled queue even after scheduled en-queue time

1.6k Views Asked by At

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

There are 1 best solutions below

6
On

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.