Database Reference
In-Depth Information
Using saga and NHibernate
We will walk through a modified example of a basic saga, originally from ht-
tps://github.com/jkillingsworth/NServiceBus-BasicSagas . However, this example has been
modified to use NHibernate, which uses a local SQL Express database. NHibernate was ad-
ded using some of the steps from http://docs.particular.net/nservicebus/relational-
persistence-using-nhibernate---nservicebus-4.x . We also added logging using the NLog
framework to log functionalities as we go. The NHibernate ORM framework was chosen
because it can connect to a multitude of different databases using the same code, the differ-
ence being the connection string in the app.config file for the different databases.
To elaborate on this saga example, there is a MySaga program that directs the messages
while saving a saga instance as the messages are being moved. The saga persistence keeps
track of the information that we defined to be saved in a saga entity object. The saga acts as
an anchor that we can persist as we orchestrate messages moving across the bus. We can re-
trieve the instance of the saga associated with the message, update it, and keep it stored,
since the original message morphs into different types of messages.
In this application, we sent IAmStartedByMessages<SubmitRequestCommand>
from the AppSubmittingRequests application, seen here as Purchase Order
Requests . It creates and submits SubmitRequestCommand , which takes the data from
this message and creates a saga on the bus with a unique ID. It also sets a 60-second timer
that will send a time-out message from the bus once the 60 seconds are completed.
Search WWH ::




Custom Search