开发者

NServiceBus using static class library

开发者 https://www.devze.com 2023-02-03 14:43 出处:网络
I\'ve got a static class library which I\'m using to provide services to an ASP.NET MVC3 application.

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 l开发者_JS百科ibrary that is the 'business logic'.


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().


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消