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

Message actions


As noted in the previous section, sometimes we will do something in a message handler relating directly to the messaging infrastructure, independent of business logic or data access.

Stopping a message

For whatever reason, we might need to not only stop a message in the current handler, but stop all pending handlers from executing as well, normally because of a message authorization scheme. In order to do that, we simply call this method:

IBus.DoNotContinueDispatchingCurrentMessageToHandlers();

When we call this method, the message is consumed successfully, and the ambient transaction will be committed. We are just electing to stop running additional handlers on it.

Deferring a message

Sometimes, we cannot process a message immediately and need to wait just a little bit. We can instruct the bus to put the message back on the queue, essentially moving it to the back of the line:

IBus.HandleCurrentMessageLater();

However, if the queue is empty at that moment, we will just wind up processing...