Book Image

Learning NServiceBus - Second Edition

By : David Boike
Book Image

Learning NServiceBus - Second Edition

By: David Boike

Overview of this book

Table of Contents (18 chapters)
Learning NServiceBus Second Edition
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Purging the queue on startup


Self-hosting NServiceBus is usually done in a web application or a smart client. Because of this, the messages received when self-hosting (if any) are usually events, and the intent of those events is usually something along the lines of "something has happened on the server, so the data you are holding in the cache is now invalid."

If a web application or smart client is offline for a period of time, as is the case when Internet Information Services (IIS) decides to spin down an idle website, a backlog of incoming messages may pile up, and it's quite possible that all of those messages will be instructions to remove items from a cache that is already empty because the application has just started up. So why would we want to bother processing these messages?

To avoid this situation, NServiceBus offers the option to purge the input queue when the endpoint starts up, as follows:

cfg.PurgeOnStartup(true);

While this option is quite common when self-hosting a web application...