【问题标题】:Scaling out SignalR with SQL Server - is it possible to add messages from an outside service?使用 SQL Server 扩展 SignalR - 是否可以从外部服务添加消息?
【发布时间】:2014-08-20 10:39:41
【问题描述】:

我将 SQL Server 用作扩展 SignalR 的背板。 在我的场景中,有一些服务在其他服务器上运行,我需要将它们的工作状态集成到我的 SignalR 集线器中。

我尝试使用 SQL 服务器横向扩展运行一个简单的控制台应用程序作为测试,并发布如下消息:

        var config = new SqlScaleoutConfiguration(connectionString);
        GlobalHost.DependencyResolver.UseSqlServer(connectionString);

        var messageBus = new SqlMessageBus(GlobalHost.DependencyResolver, config);
        var message = new Message("TransactionHub", "RegisterClient","{userId:1}");
        messageBus.Publish(message);

我可以像这样使用 SQLScaleout 吗?

如果没有,还有其他方法可以做我想做的事情吗?

编辑:

我已经按照halter73的建议做了,它工作正常,你必须注意,如果你激活一个客户端功能,你发送的参数必须匹配,即如果对象是“Namespace.ClassName”那么你应该发送完全相同类型的对象。

【问题讨论】:

    标签: c# sql-server signalr scalability


    【解决方案1】:

    您应该尝试使用GlobalHost.ConnectionManager.GetHubContext 而不是直接发布到总线。您的代码将如下所示:

    var context = GlobalHost.ConnectionManager.GetHubContext<TransactionHub>();
    context.Clients.All.registerClient(new { userId = 1 });
    

    【讨论】:

    • 应该是 GetHubContext 而不是 GetConnectionContext ?后者会导致 Clients 属性出错...
    • 那是一个错字。绝对应该是 GetHubContext。
    猜你喜欢
    • 2014-07-19
    • 2019-01-22
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    • 2020-04-30
    相关资源
    最近更新 更多