![]() |
|
What’s new in Azure SignalR 1.1.0 Preview 1 - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Programming (https://sickgaming.net/forum-76.html) +--- Forum: C#, Visual Basic & .NET (https://sickgaming.net/forum-79.html) +--- Thread: What’s new in Azure SignalR 1.1.0 Preview 1 (/thread-90686.html) |
What’s new in Azure SignalR 1.1.0 Preview 1 - xSicKxBot - 06-05-2019 What’s new in Azure SignalR 1.1.0 Preview 1 Ken June 3rd, 2019 We just shipped 1.1.0 Preview 1 of Azure SignalR Service SDK to support some new features in ASP.NET Core 3.0, including endpoint routing and server-side Blazor. Let’s take a look how you can use them in your Azure SignalR application. Here is the list of what’s new in this release:
Endpoint routing support for ASP.NET Core 3 For those who are using Azure SignalR, you should be familiar with Code: AddAzureSignalR()Code: UseAzureSignalR()A typical Azure SignalR application usually looks like this in Startup.cs (note where Code: AddAzureSignalR()Code: UseAzureSignalR()Code: public void ConfigureServices(IServiceCollection services)
{ ... services.AddSignalR() .AddAzureSignalR(); ...
} public void Configure(IApplicationBuilder app)
{ ... app.UseAzureSignalR(routes => { routes.MapHub<Chat>("/chat"); }); ...
}ASP.NET Core 3.0 introduced a new endpoint routing support which allows routable things like MVC and SignalR to be mixed together in a unified Code: UseEndpoints()For example, you can call Code: MapGet()Code: MapHub()Code: UseEndpoints()Code: app.UseEndpoints(routes =>
{ routes.MapGet("/foo", async context => { await context.Response.WriteAsync("bar"); }); routes.MapHub<Chat>("/chat");
});This new syntax is also supported in the latest Azure SignalR SDK so you don’t need to use a separate Code: UseAzureSignalR()Now your Azure SignalR application looks like this: Code: public void ConfigureServices(IServiceCollection services)
{ ... services.AddSignalR() .AddAzureSignalR(); ...
} public void Configure(IApplicationBuilder app)
{ ... app.UseRouting(); app.UseEndpoints(routes => { routes.MapHub<Chat>("/chat"); }); ...
}The only change you need to make is to call Code: AddAzureSignalR()Code: AddSignalR()This will be very useful in the case that SignalR is deeply integrated in your code base or the library you’re using. For example, when you’re using server-side Blazor. Use SignalR service in server-side Blazor apps Server-side Blazor is a new way to build interactive client-side web UI in ASP.NET Core 3. In server-side Blazor, UI updates are rendered at server side, then sent to browser through a SignalR connection. Since it uses SignalR, there is a natural need to use Azure SignalR service to handle the SignalR traffic so your application can easily scale. If you look at some server-side Blazor code samples, you’ll see they have a call to Code: MapBlazorHub()Code: app.UseEndpoints(endpoints =>
{ ... endpoints.MapBlazorHub(); ...
});The implementation of this method calls Code: MapHub()Code: MapBlazorHub()Code: AddAzureSignalR()Code: MapBlazorHub()Please follow these steps to change your server-side Blazor app to use SignalR service:
Then run your app you’ll see the WebSocket connection is going through SignalR service. Check out this repo for a complete code sample. Server stickiness The typical connection flow when using SignalR service is that client first negotiates with app server to get the url of SignalR service, then service routes client to app server. When you have multiple app servers, there is no guarantee that two servers (the one who does negotiation and the one who gets the hub invocation) will be the same one. We hear a lot of customers asking about whether it’s possible to make the two servers the same one so they can share some states between negotiation and hub invocation. In this release we have added a new “server sticky mode” to support this scenario. To enable this, you just need to set Code: ServerStickyModeCode: RequiredCode: AddAzureSignalR()Code: services.AddSignalR().AddAzureSignalR(options => { options.ServerStickyMode = ServerStickyMode.Required;
});Now for any connection, SignalR service will guarantee negotiation and hub invocation go to the same app server (called “server sticky”). This feature is very useful when you have client state information maintained locally on the app server. For example, when using server-side Blazor, UI state is maintained at server side so you want all client requests go to the same server including the SignalR connection. So you need to set server sticky mode to Code: RequiredPlease note in this mode, there may be additional cost for the service to route connection to the right app server. So there may be some negative impact in message latency. If you don’t want the performance penalty, there is another Code: PreferredCode: DisabledYou can refer to this doc for more details about server sticky mode. Ken Chen Principal Software Engineering Manager Follow Ken https://devblogs.microsoft.com/aspnet/author/kenchenmicrosoft-com/feed/ |