NServiceBus使用静态类库
我有一个静态类库,用于为 ASP.NET MVC3 应用程序提供服务。
我正在尝试了解提供异步数据库调用的最佳方法。我有一个将数据发送到节点的应用程序,该应用程序将数据传递到该节点知道的所有节点,依此类推。
我正在使用 NServiceBus2 接受来自 Web 客户端的节点消息。然后,控制权被发送回 Web 应用程序,以允许控制器完成并将页面返回给用户。
在后台,侦听器接收该消息并启动节点数据库拖网。我创建了一个新的类库,它是工作正常的监听器。
我的问题是出版。我是否必须在每次调用方法时创建总线?我可以在哪里存放巴士?我想我可以尝试 WCF 路线吗?
澄清
- 我认为直接从 Web 应用程序发出消息不是一个好主意 - 就像您可能不会将数据库代码放入控制器中一样。我想要一个单独的类库,即“业务逻辑”。
I've got a static class library which I'm using to provide services to an ASP.NET MVC3 application.
I'm trying to get my head around the best way to provide async database calls. I've got an app that sends data to a node, which passes it on to all the nodes that node knows about and so on.
I'm using NServiceBus2 to accept a node message from a web client. Control is then sent back to the web app to allow the controller to finish and hence return the page to the user.
In the background a listener picks up that message and starts the node database trawl. I've created a new class library which is the listener which works fine.
My problem is publishing. Do I have to create the Bus on every call to a method? Where can I store the bus? I suppose I could try the WCF route?
Clarifications
- I don't think it's a great idea to raise messages directly from a web application - in the same way you probably wouldn't put DB code in the controller. I'd like to have a separate class library that is the 'business logic'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种方法可以从 ASP.NET Web 应用程序获取总线上的消息。首先,您可以在全局位置(global.asax或其他)引导总线一次并提供对其的引用。我们更喜欢通过某种抽象来引用总线,通常是诸如 ServiceAgent之类的类。其中 T 是您将在内部使用 Bus.Send() 发送的消息。如果您不想在 Web 应用程序中增强总线,另一个选项是将 NServiceBus 端点公开为 WCF 服务。这只需通过使用 WcfService实现一个类即可完成。从那里您可以简单地调用公开的 SOAPy 服务。如果您不喜欢 SOAP,则可以以不同方式配置端点。然后,您可以在端点内执行 Publish()。
There are a couple of ways to get messages on the Bus from a ASP.NET web app. Firstly you can bootstrap the Bus once in a global place(global.asax or otherwise) and provide a reference to it. We prefer to reference the Bus via some abstraction, typically a class such as ServiceAgent<T> where T is a message you will internally Bus.Send(). If you don't want to boostrap the Bus in your web app, the other option is to expose your NServiceBus endpoint as a WCF service. This is done simply by implementing a class with the WcfService<TRequest,TResponse>. From there you can simply call the exposed SOAPy service. If you don't like SOAP, you can configure the endpoint differently. From within your endpoint you can then do a Publish().
您为每个服务创建一个总线。服务可以是 Windows 服务、win-forms 应用程序,或者在您的情况下是网站。
在网站/Web服务场景中,我通常在global.asax的application_start事件中创建总线。
您可以将总线保存在容器中,例如 StructureMap 或 Castle Windsor。
不要直接从您的网站发布消息,而是调用发布消息的 WCF 服务。或使用从您的网站发送。花点时间了解 nservicebus 消息传递的不同用法。特别是发布/订阅和发送/回复场景的差异,何时使用什么是必要的。
对于您的其他文字:我不明白您的情况。如果您还有其他问题,请编辑您的原始帖子以帮助我们理解。
you create a bus per service. a service can be a windows service, a win-forms application or in your case a website.
in a website/webservice scenario i normally create the bus in the application_start event of the global.asax.
you can save the bus in a container for example StructureMap or Castle Windsor.
don't publish messages from your website directly instead call a wcf service that publishes a message. or use send from your website. take your time to understand the different usages of messaging with nservicebus. specifically the differences of pub/sub and send/reply scenarios when to use what is essential.
to your other text: i don't understand your scenario. if you have further problems please edit your original post to help us understand.