开发者

Communication between multiple web applications using SignalR

开发者 https://www.devze.com 2023-04-12 12:29 出处:网络
I have two different web applications that need to communi开发者_如何学Gocate with each others (which I can currently accomplish by using Silverlight Duplex but that doesn\'t scale very well).After re

I have two different web applications that need to communi开发者_如何学Gocate with each others (which I can currently accomplish by using Silverlight Duplex but that doesn't scale very well). After reading about SignalR, I'd like to give this a try but failed to find much documentation on how to do this. Any advice on ho to get started would be greatly appreciated.

Thanks!

More specific Info: Example: Application A (Bidding Interface) - A web page to allow multiple end-users to place bids on certain items.

Application B (Managing Interface) - A web page to allow a user (or could potentially be multiple users) to monitor/control the actions from Bidding Interface.

So when a user from Application A place a bid on a piece, I'll need a way to alert Application B that a bid has been placed. Then from Application B, should the user choose to accept the bid, I need to send an alert back to Application A (to update current price, increase bid etc...)


In all honesty, in might just be simpler to have each application push the notifications to each other via standard service calls (WCF, ASMX, HTTP handler endpoints, MVC controllers, whatever). SignalR is useful in browser to server communications because there isn't a consistent way to do push from the server to a connected browser. But from web app to web app pushing is simple; Application A just calls a service endpoint on Application B to notify it of something happening.


Assuming that what you want is something like ...

User (browser) --- Application A --- Application B --- User (Browser)

Realtime communication can be done by doing the following ...

This isn't the job of signalR however something like NServiceBus would fit this very well.

you reference a bus dll file and hubs can both raise and respond to events. In your case you would have both SignalR and your Service Bus technology work together to allow the cross application sync.

So the process is something like ...

  1. User in application A fires up browser and requests page.
  2. Application A creates Hub instance which internally subscribes to Service Bus events
  3. User in application B fires up browser and requests page.
  4. Application B creates Hub instance which internally subscribes to Service Bus events
  5. User on either application does some action resulting in SignalR picking up a message.
  6. SignalR raises bus event to say "This user did something" on the service bus.
  7. Other Hub on other Application through subscribription to the event gets notified of the event and takes any action to inform its connected users of it.

Lesson to be learnt here ... Don't try and make a technology do something beyond its purpose ... use the right tool for the job.

This entire solution can be done with little more than about 20 lines of code after getting the core framework setup.

NServiceBus can be found here:

http://particular.net/nservicebus

Disclaimer: There may be other solutions but this one suggestion don't assume this is the only way this can be solved, and the only technologies that be used in this manner. I am not affiliated in any way with Particular or the NServiceBus product.

0

精彩评论

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

关注公众号