Sharing a SignalR hub between a WebApi and MVC project

♀尐吖头ヾ 提交于 2019-12-12 07:13:13

问题


Is there a recommended approach to sharing a SignalR hub across two applications?

The actual situation is a public facing WebAPI project and an internal MVC WebApp. What I'd like to do is call methods on a SignalR hub from the WebAPI project and have the results of these methods pushed to clients connected via the MVC app.

Would the best option be to create a third 'Hub' project and have both projects connect to that? If so, how are the hub instances managed? Can both applications get a reference to the same hub from distinct app pools (and possibly hosts)?

I read a little bit about GlobalHost.ConnectionManager.GetHubContext, would this suffice to get a effectively a singleton hub which both apps could use?

Any thoughts greatly appreciated.


回答1:


Just setup signalr message routing through a SQL Server table. It will automatically connect all hubs using the same routing setup. Nothing else to do, it's magic.

GlobalHost.DependencyResolver.UseSqlServer(ConfigurationManager.ConnectionStrings["signalr"].ConnectionString);

You will need the following nuget package: Microsoft.AspNet.SignalR.SqlServer



来源:https://stackoverflow.com/questions/18704784/sharing-a-signalr-hub-between-a-webapi-and-mvc-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!