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
ExpiresAtUtc
is assigned to year 9999 by default – Mikhail ShilkovExpiresAtUtc
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