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

Specifying the handler order


Because of polymorphic dispatch, it's possible that there could be multiple handlers within an endpoint that all act upon the same message because of the inheritance chain for that message. In addition, it's possible to deploy several handlers for the same type to the same endpoint, although as each handler adds to the amount of work that must be done within a transaction, this isn't always the best idea.

In these cases, all relevant handlers for a message are organized in a pipeline. One transaction is created, and then each handler is executed for that message, one after the other. There is no guarantee what order the handlers will run in, as all the handlers should do their work autonomously.

At some point, it may become necessary to control the order in which handlers run. This is, in most cases, a code smell, as it indicates that your message handlers are not truly autonomous. Perhaps, if handlers must run in a specific order, they should be refactored into...