0

I attended Udi Dahan's lecture at ndc 2009 in Norway - Making Patterns Complete. Now I want to replace my all my repositories with MessageHandlers in Nservicebus. I am using Nhibernate, but I don't know where to put BeginTranscactin/commit and OpenSession. Should each messagehandler contain begintransaction and openSession ?
What about a pipeline of Messages that are running in a synchronized manner ?
And I guess it's not possible to open the session outside of the message and pass it as a property on the message - since the caller and the server are running in two different processes.

Example of messagehandlers:

IGetOrderHeaders , returns order without orderlines
IGetOrderWithOrderlines , returns order with orderlines
ITakeOrderByTruck, the current truck aquires the order from the pool
IUnloadPalletFromCarByTruck, unloads a pallet from a car
IPutPalletAtLocationByTruck, place a pallet at location
IMakeOrderDoneByTruck, sets the orderstatus to done by current truck

I have also considered using Prism serverside instead of nservicebus - this works actually quite good, though it's not intented to use it serverside. But the ideal solution would be nservicebus.

4

1 回答 1

2

您可以通过实现一个消息模块 (IMessageModule) 来做到这一点。看看 NHibernate saga 持久化器使用的 NHibernateMessageModule:

主干\src\impl\SagaPersisters\NHibernateSagaPersister\NServiceBus.SagaPersisters.NHibernate

您可以在 sessionfactory 中缓存会话(如上面的示例),也可以使用其“ThreadStatic”缓存模式将其存储在您喜欢的容器中。

NServiceBus 在 TransactionScope 中运行所有处理程序,以便自动为您处理事务!

希望这可以帮助!

于 2010-01-08T13:21:47.010 回答