在 nservicebus 中将 begintransaction 和 opensession 放在哪里
我参加了 Udi Dahan 在 2009 年挪威 ndc 上的演讲——Making Patterns Complete。 现在我想用 Nservicebus 中的 MessageHandlers 替换我的所有存储库。 我正在使用 Nhibernate,但我不知道将 BeginTranscactin/commit 和 OpenSession 放在哪里。 每个消息处理程序是否应该包含 begintransaction 和 openSession ?
以同步方式运行的消息管道怎么样?
我想不可能在消息之外打开会话并将其作为消息的属性传递 - 因为调用者和服务器在两个不同的进程中运行。
消息处理程序示例:
IGetOrderHeaders ,返回没有订单行的订单
IGetOrderWithOrderlines ,返回带有订单行的订单
ITakeOrderByTruck,当前卡车从池中获取订单
IUnloadPalletFromCarByTruck,从汽车上卸载托盘
IPutPalletAtLocationByTruck,将托盘放置在位置
IMakeOrderDoneByTruck,将订单状态设置为由当前卡车完成
我还考虑过使用 Prism 服务器端而不是 nservicebus - 这实际上非常好,尽管它无意在服务器端使用它。但理想的解决方案是 nservicebus。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过实现消息模块 (IMessageModule) 来实现此目的。看一下 NHibernate saga 持久化器使用的 NHibernateMessageModule:
trunk\src\impl\SagaPersisters\NHibernateSagaPersister\NServiceBus.SagaPersisters.NHibernate
您可以将会话缓存在 sessionfactory 中(如上面的示例),也可以将其存储在您的会话工厂中。最喜欢的容器使用其“ThreadStatic”缓存模式。
NServiceBus 在 TransactionScope 中运行所有处理程序,以便自动为您处理事务!
希望这有帮助!
You do this by implementing a messagemodule (IMessageModule). Take a look at the NHibernateMessageModule that is used by the NHibernate saga persister:
trunk\src\impl\SagaPersisters\NHibernateSagaPersister\NServiceBus.SagaPersisters.NHibernate
You can either cache the session in the sessionfactory (like the sample above) or store it in your favorite container using its "ThreadStatic" cache mode.
NServiceBus runs all handlers in a TransactionScope so that will take care of the transaction for you automatically!
Hope this helps!