Discarding expired messages

Component: SQL Server Transport
NuGet Package NServiceBus.SqlServer (2.x)
Target NServiceBus Version: 5.x


The messages with Time-To-Be-Received (TTBR) set are stored in the queue table just like regular messages. The only difference is that the Expires column is set to the time (in UTC) when the message expires. The calculation of expiry time is done on the database level so that clock drifts between endpoints don't affect the TTBR.


The messages with specified Time-To-Be-Received (TTBR) are pushed through the message pump, just like regular messages, regardless if their TTBR already elapsed or not. The receive query returns the difference between the expiry time and the current UTC time in the database so that the transport can make a decision if a given message has expired. Calculating the difference on the database level prevents the TTBR feature from being affected by potential clock drift of machines running sender and receiver endpoints.

In addition to that, the expired messages are removed from the queue by a scheduled job which runs every 5 minutes. Each run the job attempts to remove all expired messages, in batches, using series a delete statements. Each batch is limited to 10000 messages.

Last modified