我正在使用 React 前端在 ASP.NET Core 2.2 应用程序中实现 Azure SignalR 服务。当我发送消息时,我没有收到任何错误,但我的消息未到达 Azure SignalR 服务。
具体来说,这是一个私人聊天应用程序,因此当消息到达中心时,我只需将其发送给该特定聊天中的参与者,而不是发送给所有连接。
当我发送消息时,它会到达我的集线器,但我没有看到任何迹象表明该消息正在发送到 Azure 服务。
为了安全起见,我使用Auth0JWT Token身份验证。在我的中心,我正确地看到了授权用户声明,因此我认为不存在任何安全问题。正如我所提到的,我能够访问中心的事实告诉我,前端和安全性工作正常。
然而,在 Azure 门户中,我没有看到任何消息的迹象,但如果我正确读取数据,我确实会看到 2 个客户端连接,这在我的测试中是正确的,即我用于测试的两个打开的浏览器。这是一个屏幕截图:
这是我的Startup.cs代码:
public void ConfigureServices(IServiceCollection services)
{
// Omitted for brevity
services.AddAuthentication(options => {
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(jwtOptions => {
jwtOptions.Authority = authority;
jwtOptions.Audience = audience;
jwtOptions.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"];
// Check to see if the message is coming …Run Code Online (Sandbox Code Playgroud) azure signalr asp.net-core asp.net-core-signalr azure-signalr
我正在学习 SignalR 但遇到了障碍。
我有一个 Azure 函数,已成功发布到 Azure SignalR 托管服务(在无服务器模式下配置)
我一直在关注这个快速入门:
快速入门:使用 C# 通过 Azure Functions 和 SignalR 服务创建聊天室
我想要实现的基本上是将来自服务器的消息接收到我的客户端应用程序中。为了原型化,我创建了一个控制台应用程序。
我添加了以下 Nuget 包
Microsoft.AspNetCore.SignalR.Client -版本 1.1.0 Microsoft.Azure.WebJobs.Extensions.SignalRService
所有基础设施似乎都工作正常 - 我的假设是我可以在以下地址运行演示网站,将其指向我的本地实例(或托管在 Azure 中的实例) https://azure- samples.github.io/signalr-service-quickstart-serverless-chat/demo/chat-v2/
我的 AzureFunction 发布的消息直接发布到聊天窗口中。
如何将这些消息打印到控制台?
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Azure.WebJobs.Extensions.SignalRService;
using System;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.ReadKey();
var connection = new HubConnectionBuilder().WithUrl("http://localhost:7071/api").Build();
connection.On<SignalRMessage>("newMessage", (message) =>
{
Console.WriteLine(message.Arguments);
});
connection.On("newMessage", (string server, string message) =>
{
Console.WriteLine($"Message from …Run Code Online (Sandbox Code Playgroud) 我在我的一个 ASP.NET Core MVC 应用程序 (.NET 6) 中使用 ASP.NET Core SignalR,该应用程序作为 Web 应用程序托管在 Azure 上。
我正在努力寻找有关在 SignalR 无法接受更多连接之前我的网络应用程序可以处理多少并发连接的信息。
我知道 Azure 提供付费 Azure SignalR 服务,该服务从 1000 个并发连接开始计费。这是否表明我的设置最多只能支持 1000 个连接?到目前为止,400个并发连接已经完美运行。
使用 .Net Core Signal R、Azure SignalR。代码用来工作。停止工作。
在 await MyHubConnection.StartAsync() 时失败;
引发异常 System.TypeLoadException:来自程序集“Microsoft.AspNetCore.SignalR.Client.Core,版本=1.1.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”的“ConnectionState”类型中的“Method 'GetStreamItemType' 没有实现。”
Microsoft.AspNetCore.SignalR.Client v 1.1.0 Microsoft.Azure.SignalR 1.0.7
如何解决这个问题?
谢谢!
Adam Leffert www.leffert.com
想问一下有没有可以获取Azure SignalR连接字符串的ARM模板函数。
我发现我们收到此错误:
Failed to invoke 'CreateChatRequest' due to an error on the server. HubException: Method does not exist.
at _this.callbacks.<computed> (chat.min.js:2060)
at HubConnection.processIncomingData (chat.min.js:2154)
at WebSocketTransport.HubConnection.connection.onreceive (chat.min.js:1881)
at WebSocket.webSocket.onmessage (chat.min.js:3922)
Run Code Online (Sandbox Code Playgroud)
该方法确实存在。该代码确实有效,然后经过一段时间的测试,它会返回此内容并且不会停止。
似乎可以暂时解决问题的是重新启动 Azure SigR 服务,但它又回来了。在开发过程中以本地 SigR 为目标时不会出现此问题;它只发生在 Azure SigR 上。
根据文档,当服务器上出现错误时,这似乎是一个包罗万象的错误,但没有记录任何异常。我已经打开了详细的错误,但这并没有改变从服务器返回的错误。我还尝试捕获异常并发回 HubException 以查看发生了什么,但这也没有改变错误消息。
TIA 寻求任何帮助。
我有一个 .Net Core 3.0 控制台项目,其中包含 WebJob 函数,该函数具有与 Azure Signal R 的输出绑定。该应用程序构建正常,但是当我运行它并尝试通过 SignalR 发送消息时,出现以下错误:
{System.MissingMethodException: Method not found: 'System.String Microsoft.Azure.SignalR.AuthenticationHelper.GenerateAccessToken(System.String, System.String, System.Collections.Generic.IEnumerable`1<System.Security.Claims.Claim>, System.TimeSpan, System.String)'.
at Microsoft.Azure.SignalR.Management.RestApiAccessTokenGenerator.Generate(String audience, Nullable`1 lifetime)
at Microsoft.Azure.SignalR.Management.RestApiProvider.GenerateRestApiEndpoint(String path, Nullable`1 lifetime)
at Microsoft.Azure.SignalR.Management.RestApiProvider.GetSendToGroupEndpoint(String groupName, Nullable`1 lifetime)
at Microsoft.Azure.SignalR.Management.RestHubLifetimeManager.SendGroupAsync(String groupName, String methodName, Object[] args, CancellationToken cancellationToken)
at Microsoft.AspNetCore.SignalR.Internal.GroupProxy`1.SendCoreAsync(String method, Object[] args, CancellationToken cancellationToken)
at Microsoft.Azure.WebJobs.Extensions.SignalRService.AzureSignalRClient.SendToGroup(String groupName, SignalRData data)
at Microsoft.Azure.WebJobs.Extensions.SignalRService.SignalRAsyncCollector`1.AddAsync(T item, CancellationToken cancellationToken)
at InSysWebJobP300DataProcessor.Helper.ProcessMinuteData(Message message, ConnectionMultiplexer redisConnection, IAsyncCollector`1 signalRMessages, ILogger log) in E:\InergySystems\GitHub\InSysCore\InSysWebJobP300DataProcessor\Helper.cs:line 125}
Run Code Online (Sandbox Code Playgroud)
SignalR 服务在 Program.Main 中注册为: …
我正在尝试学习如何使用Azure function和SignalR创建无服务器设计。为此,我创建了以下类Azure function:
public static class NotifactionR
{
[FunctionName("negotiate")]
public static SignalRConnectionInfo Negotiate(
[HttpTrigger(AuthorizationLevel.Anonymous)]HttpRequest req,
[SignalRConnectionInfo(HubName = "my-hub")]
SignalRConnectionInfo connectionInfo)
{
// connectionInfo contains an access key token with a name identifier claim set to the authenticated user
return connectionInfo;
}
[FunctionName("NotifactionR")]
public static Task NotifactionR([EventGridTrigger]EventGridEvent eventGridEvent,
[SignalR(HubName = "my-hub")]IAsyncCollector<SignalRMessage> signalRMessages,
ILogger log)
{
log.LogInformation(eventGridEvent.Data.ToString());
return signalRMessages.AddAsync(
new SignalRMessage
{
// the message will only be sent to these user IDs
UserId = "userId1", …Run Code Online (Sandbox Code Playgroud) 如何测试托管在 Azure 应用服务上的 SignalR 应用程序(负载 + 功能组合) 我们正在构建一个 SignalR 应用程序,用于在活动和大会期间(实时)向观众进行问卷调查。我们预计有 1000-2000 个活跃并发用户的会话,这意味着大多数用户将同时连接。这会导致短时间内的重负载。我们想要模拟 x 个同时连接的唯一客户端。例如,1000 个用户在 30 秒内连接。语言和 signalR 包:该应用程序是使用 .NET Core 2.2 和 React 前端构建的。*SignalR 包 (.NET) Microsoft.AspNetCore.SignalR.Core (1.1.0) *SignalR 包 (npm) @aspnet/signalr (1.1.4) Azure 设置 我们正在使用 Azure SQL DB 的 Azure Appservice 上运行我们的应用程序。我们正在使用 Azure SignalR 服务,并将根据客户的需求进行扩展。
测试我们尝试使用Jmeter进行负载测试,并进行了GUI测试(使用Selenium进行小规模100-200个用户)。我们还运行了一个应用程序内测试,通过 JavaScript 循环创建集线器连接。但我们无法确保我们的应用程序能够在 1000-2000 个活动连接下运行。我的问题是如何测试这种类型的应用程序并确认它。我不可能是第一个构建这样的应用程序的人。
我有一个客户端(角度)应用程序服务和一个 api(net core 3.1)应用程序服务,我试图通过 signalr 相互通信。它在带有 websocket 的 localhost 上运行良好,但在 azure 应用程序服务上,它仅适用于长轮询传输模式,即使我在配置中启用了 websocket。协商返回 200 以及 connectionId 和所有三个可用传输。但是wss请求返回404,如下所示。
WebSocket connection to 'wss://xxxx.azurewebsites.net/notifications?id=ZI0-a_p5G6YziWhCxxc7Kg&access_token=eyJhbGc.. failed: Error during WebSocket handshake: Unexpected response code: 404
Utils.js:218 [2021-03-25T18:21:13.045Z] Error: Failed to start the transport 'WebSockets': Error: There was an error with the transport.
Run Code Online (Sandbox Code Playgroud)
我尝试查看大量资源和文档来解决这个问题,因此我们将不胜感激。这是我的配置:
在startup.cs中
options.AddPolicy(MyAllowSpecificOrigins,
builder =>
{
builder.WithOrigins("https://xxxxx-dev.azurewebsites.net").AllowAnyMethod().AllowAnyHeader().AllowCredentials();
builder.WithOrigins("http://localhost:4200").AllowAnyMethod().AllowAnyHeader().AllowCredentials();
});
....
services.AddControllers();
services.AddSignalR();
....
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<NotificationHub>("/notifications");
});
Run Code Online (Sandbox Code Playgroud)
在客户端
import { HubConnectionBuilder } from '@microsoft/signalr';
....
this.hubConnection = new HubConnectionBuilder()
.withUrl("https://xxxx-dev.net/notifications",
{ …Run Code Online (Sandbox Code Playgroud) azure-signalr ×10
azure ×7
signalr ×5
c# ×4
asp.net-core ×2
.net ×1
.net-core ×1
load-testing ×1
signalr-hub ×1