Discarding expired messages

Target Version: NServiceBus 5.x
Standard support for version 5.x of NServiceBus has expired. For more information see our Support Policy.


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.


Messages with Time-To-Be-Received (TTBR) specified are pushed through the message pump, just like regular messages, regardless of 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, 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 delete statements. Each batch is limited to 10000 messages.

Last modified