NH + Rhino ESB = Headache?
I was to make Rhino Service Bus work with NHibernate the other day. Although, Nhibernate and Rhino Service Bus each work flawlessly, when coupled together the problem started. What I wanted to do was simple. Gather some orders to make a package large enough for shipment gateway to process.
As soon as I hit the database to check if I have enough orders to create a shipment package, strange errors occurred. What I did when a new order is received was this:
public class ShipmentSaga : ConsumerOf<NewOrderMessage>
As soon as the execution of HasEnoughOrders finished and system tried to dispose and close the session, an exception occurred saying : “Disconnect cannot be called while a transaction is in progress”. Ayende says this is the problem of NHibernate handling TransactionScopes. NH registers the session for DTC transactions but it does not defer the transaction’s disposal the way it should. Hopefully the bug will be fixed in future releases of NH and there is a workaround. To “temporarily” avoid this problem, do not explicitly dispose the session:
private bool HasEnoughOrders()
Rhino Service Bus is still under development so there might be other minor issues when used together with other technologies and frameworks, but it is a great piece of software. If you’re not familiar with Rhino Tool set, you definitely need to take a look. Thank you Ayende for creating such a great toolkit.