Multiple SignalR hubs with different configurations

我怕爱的太早我们不能终老 提交于 2019-12-24 10:48:02

问题


I've run into a situation where I need multiple SignalR hubs (at least 2) with different configurations.

Currently with v1.1.0 I can only do things like the following which configures all hubs:

GlobalHost.Configuration.ConnectionTimeout = TimeSpan.FromSeconds(30);

Is it possible to set different configurations for multiple hubs?


回答1:


All hubs share the same connection object therefore they all share the same configuration.

If you want to have 1 server but multiple connection configurations for hubs you can do the following:

app.MapHubs(yourPathToConnectionWithConfigurationA, new HubConfiguration
{
    Resolver = MyResolverWithConfigurationA
});

app.MapHubs(yourPathToConnectionWithConfigurationB, new HubConfiguration
{
    Resolver = MyResolverWithConfigurationB
});

Therefore when you want to use configuration A you connect to that server end point and when you want to connect to endpoint B you connect to that endpoint. Keep in mind the hubs will not share clients/connections across the two configurations even though the hubs will be on both.



来源:https://stackoverflow.com/questions/17623962/multiple-signalr-hubs-with-different-configurations

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