简体   繁体   English

SignalR通过Azure Service Bus

[英]SignalR via Azure Service Bus

I must be missing something when setting up SignalR to use an Azure Service Bus. 设置SignalR以使用Azure Service Bus时,我必须遗漏一些东西。 I have my App Service (API - Web API 2) setup to run 3 constant instances (currently), upon startup, the API uses the Service Bus connection string and sets the appropriate topic prefix. 我有我的App Service(API - Web API 2)设置来运行3个常量实例(当前),启动时,API使用Service Bus连接字符串并设置适当的主题前缀。

On the front-end, SignalR is able to connect to my API, but messages are only sometimes received by the client. 在前端,SignalR能够连接到我的API,但消息有时仅由客户端接收。 My assumption is that the client only receives messages from the server to which it originally connected. 我的假设是客户端只接收来自它最初连接的服务器的消息。 This leads me to believe that SignalR is not using the Service Bus correctly. 这让我相信SignalR没有正确使用服务总线。 When viewing the Service Bus via Azure, I do see that topics are being created, but there are no messages in any of them (I also see subscriptions). 通过Azure查看服务总线时,我确实看到正在创建主题,但其中没有任何消息(我也看到订阅)。

So, as far as I can tell, SignalR between the client and server is still using a direct connection instead of going through the Service Bus. 所以,据我所知,客户端和服务器之间的SignalR仍然使用直接连接而不是通过服务总线。 Note that the client is using the URL of the API for the SignalR connection -- is this correct? 请注意, 客户端正在使用API​​的URL来进行SignalR连接 - 这是正确的吗?

SignalRConfig (During app startup.) SignalRConfig (在app启动期间。)

var serviceBusConnectionString = configHelper.SignalR.ServiceBusConnectionString;
var serviceBusTopicPrefix = configHelper.SignalR.TopicPrefix;

Logger.Info("SignalR: configuring");

// Use the service bus, if specified.
if (serviceBusConnectionString != null && serviceBusTopicPrefix != null) {
    Logger.Info("SignalR: using service bus");

    GlobalHost.DependencyResolver.UseServiceBus(serviceBusConnectionString, serviceBusTopicPrefix);
}

app.MapSignalR();

The above code runs for each instance, I have no idea if this is correct or not. 上面的代码针对每个实例运行,我不知道这是否正确。 Perhaps that is why I am seeing multiple topics, eg signalr_topic_my-app-staging_0 -- 0 through 5. 也许这就是我看到多个主题的原因,例如signalr_topic_my-app-staging_0 - 0到5。

Note that I've tried to follow this (outdated) tutorial: https://docs.microsoft.com/en-us/aspnet/signalr/overview/performance/scaleout-with-windows-azure-service-bus 请注意,我试图遵循这个(过时的)教程: https//docs.microsoft.com/en-us/aspnet/signalr/overview/performance/scaleout-with-windows-azure-service-bus

Your code seems correct and it should run for each instance. 您的代码似乎正确,它应该为每个实例运行。

There should be 6 topics in Service Bus: signalr_topic_{TOPIC_PREFIX}_0 through to signalr_topic_{TOPIC_PREFIX}_5. Service Bus中应该有6个主题:signalr_topic_ {TOPIC_PREFIX} _0到signalr_topic_ {TOPIC_PREFIX} _5。

Is each instance using the same topic prefix name? 每个实例是否使用相同的主题前缀名称? If they are using different topic names then this would explain the behavior you are seeing. 如果他们使用不同的主题名称,那么这将解释您所看到的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM