简体   繁体   中英

Using SignalR with Azure Service Fabric

Is it possible to use signalR with Service Fabric provided by Microsoft? I'm trying to connect an UWP app and an angularJS app to my stateless reliable service hosted in an Azure Cluster through signalR/websocket connection. But both are not able to open such a connection. On my local machine everything works fine.

Is there anything special to consider of using signalR/websockets with Service Fabric? Is there any example?

You need to enable cross-domain setting for signalR to call it from other applications.

 appBuilder.Map("/signalr", map =>
        {

            map.UseCors(CorsOptions.AllowAll);
            var hubConfiguration = new HubConfiguration()
            {
                EnableJSONP = true,
                EnableDetailedErrors = true,
                EnableJavaScriptProxies  = true
            };

            map.RunSignalR(hubConfiguration);
        });

This code can be found in the readme.txt file we get after installing the Nuget package for the SignalR. For cross domain feature, you need to install the Cores nuget package also.

After deploying this application, you can see that some calls to signalR fails and Some succeeds. By default the instance count in Reliable stateless service is -1. Thus multiple instances will be created for the service.

From signaleR Connection.Start() method three SingalR APIs will be called. These calls should happen within the same session in-order to work it properly. When we call these three API in Service Fabric with multiple instances, the call might be processed in different nodes and thus different sessions which leads to failure in singalR connection.

One solution is to Make the instance count 1 for the stateless service fabric application. I don't think that this is an elegant solution.

You need to configure the load balancer to the client ip. Then the user will always get to the same node and other users to other nodes. The user to node relationship will be persistent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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